summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader
authorllornkcor <llornkcor>2002-12-20 01:35:01 (UTC)
committer llornkcor <llornkcor>2002-12-20 01:35:01 (UTC)
commit876e1a4724a7bd75dc642e295de354241096e028 (patch) (side-by-side diff)
treea37c5dcc9d78e04bb6b859ab89d8cf81e6745087 /noncore/apps/opie-reader
parent5fd6636ba3d94b48dd543887316c47c5388a43c2 (diff)
downloadopie-876e1a4724a7bd75dc642e295de354241096e028.zip
opie-876e1a4724a7bd75dc642e295de354241096e028.tar.gz
opie-876e1a4724a7bd75dc642e295de354241096e028.tar.bz2
update - sorry it took so long. hope this works correctly
Diffstat (limited to 'noncore/apps/opie-reader') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Aportis.cpp2
-rw-r--r--noncore/apps/opie-reader/Aportis.h10
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp310
-rw-r--r--noncore/apps/opie-reader/Bkmks.h37
-rw-r--r--noncore/apps/opie-reader/BuffDoc.cpp248
-rw-r--r--noncore/apps/opie-reader/BuffDoc.h30
-rw-r--r--noncore/apps/opie-reader/CBuffer.cpp4
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.cpp264
-rw-r--r--noncore/apps/opie-reader/CDrawBuffer.h27
-rw-r--r--noncore/apps/opie-reader/CExpander.h87
-rw-r--r--noncore/apps/opie-reader/CFilter.cpp127
-rw-r--r--noncore/apps/opie-reader/CFilter.h18
-rw-r--r--noncore/apps/opie-reader/Filedata.h51
-rw-r--r--noncore/apps/opie-reader/FontControl.cpp37
-rw-r--r--noncore/apps/opie-reader/FontControl.h47
-rw-r--r--noncore/apps/opie-reader/GraphicWin.h65
-rw-r--r--noncore/apps/opie-reader/Navigation.cpp98
-rw-r--r--noncore/apps/opie-reader/Navigation.h16
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.cpp290
-rw-r--r--noncore/apps/opie-reader/Palm2QImage.h7
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp540
-rw-r--r--noncore/apps/opie-reader/QTReader.h56
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.cpp1693
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.h50
-rw-r--r--noncore/apps/opie-reader/StateData.h32
-rw-r--r--noncore/apps/opie-reader/StyleConsts.cpp99
-rw-r--r--noncore/apps/opie-reader/StyleConsts.h192
-rw-r--r--noncore/apps/opie-reader/Text.h28
-rw-r--r--noncore/apps/opie-reader/ZText.h35
-rw-r--r--noncore/apps/opie-reader/cbkmkselector.h4
-rw-r--r--noncore/apps/opie-reader/config.h4
-rw-r--r--noncore/apps/opie-reader/fileBrowser.cpp3
-rw-r--r--noncore/apps/opie-reader/infowin.cpp5
-rw-r--r--noncore/apps/opie-reader/main.cpp6
-rw-r--r--noncore/apps/opie-reader/name.h8
-rw-r--r--noncore/apps/opie-reader/opie-reader.pro129
-rw-r--r--noncore/apps/opie-reader/opie.h6
-rw-r--r--noncore/apps/opie-reader/pdb.cpp12
-rw-r--r--noncore/apps/opie-reader/plucker.cpp1280
-rw-r--r--noncore/apps/opie-reader/plucker.h73
-rw-r--r--noncore/apps/opie-reader/ppm_expander.cpp2
-rw-r--r--noncore/apps/opie-reader/ppm_expander.h12
-rw-r--r--noncore/apps/opie-reader/ustring.h12
-rw-r--r--noncore/apps/opie-reader/version.h2
-rw-r--r--noncore/apps/opie-reader/ztxt.cpp2
-rw-r--r--noncore/apps/opie-reader/ztxt.h42
46 files changed, 4580 insertions, 1522 deletions
diff --git a/noncore/apps/opie-reader/Aportis.cpp b/noncore/apps/opie-reader/Aportis.cpp
index 1327ff8..b4988da 100644
--- a/noncore/apps/opie-reader/Aportis.cpp
+++ b/noncore/apps/opie-reader/Aportis.cpp
@@ -90,7 +90,7 @@ CList<Bkmk>* Aportis::getbkmklist()
return t;
}
-int Aportis::openfile(const char *src)
+int Aportis::OpenFile(const char *src)
{
// printf("In openfile\n");
int ret = 0;
diff --git a/noncore/apps/opie-reader/Aportis.h b/noncore/apps/opie-reader/Aportis.h
index 1ca5e73..af1fd3b 100644
--- a/noncore/apps/opie-reader/Aportis.h
+++ b/noncore/apps/opie-reader/Aportis.h
@@ -75,6 +75,14 @@ class Aportis : public CExpander, Cpdb {
unsigned char circbuf[2048];
char bCompressed;
public:
+ virtual void suspend()
+ {
+ CExpander::suspend(fin);
+ }
+ virtual void unsuspend()
+ {
+ CExpander::unsuspend(fin);
+ }
virtual void sizes(unsigned long& _file, unsigned long& _text)
{
_file = dwLen;
@@ -83,7 +91,7 @@ public:
virtual bool hasrandomaccess() { return true; }
virtual ~Aportis() {}
Aportis();
- virtual int openfile(const char *src);
+ virtual int OpenFile(const char *src);
virtual int getch();
virtual unsigned int locate();
virtual void locate(unsigned int n);
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
index 30d2881..998601a 100644
--- a/noncore/apps/opie-reader/Bkmks.cpp
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -1,3 +1,4 @@
+#include "name.h"
#include <qmessagebox.h>
#include "Bkmks.h"
@@ -9,26 +10,56 @@
const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
+Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : m_position(_p)
+{
+ init(_nm, _nmlen, _anno, _annolen, _p);
+}
+
+Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p)
+{
+ init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p);
+}
Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
{
- int len = ustrlen(_nm)+1;
- m_name = new tchar[len];
- for (int i = 0; i < len; i++) m_name[i] = _nm[i];
if (_anno == NULL)
{
- m_anno = new tchar[1];
- m_anno[0] = 0;
+ tchar t = 0;
+ init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p);
}
else
{
- len = ustrlen(_anno)+1;
- m_anno = new tchar[len];
- for (int i = 0; i < len; i++) m_anno[i] = _anno[i];
+ init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p);
}
}
+void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p)
+{
+ m_namelen = _nmlen;
+ if (m_namelen > 0)
+ {
+ m_name = new unsigned char[m_namelen];
+ memcpy(m_name, _nm, m_namelen);
+ }
+ else
+ {
+ m_name = NULL;
+ }
+
+ m_annolen = _annolen;
+ if (m_annolen > 0)
+ {
+ m_anno = new unsigned char[m_annolen];
+ memcpy(m_anno, _anno, m_annolen);
+ }
+ else
+ {
+ m_anno = NULL;
+ }
+ m_position = _p;
+}
+
Bkmk::~Bkmk()
{
if (m_name != NULL) delete [] m_name;
@@ -41,67 +72,93 @@ Bkmk& Bkmk::operator=(const Bkmk& rhs)
{
if (m_name != NULL)
{
- delete [] m_name;
- m_name = NULL;
+ delete [] m_name;
+ m_name = NULL;
}
if (m_anno != NULL)
{
- delete [] m_anno;
- m_anno = NULL;
+ delete [] m_anno;
+ m_anno = NULL;
}
if (rhs.m_name != NULL)
{
- int len = ustrlen(rhs.m_name)+1;
- m_name = new tchar[len];
- for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i];
+ m_namelen = rhs.m_namelen;
+ m_name = new unsigned char[m_namelen];
+ memcpy(m_name, rhs.m_name, m_namelen);
}
else
- m_name = NULL;
+ m_name = NULL;
if (rhs.m_anno != NULL)
{
- int len = ustrlen(rhs.m_anno)+1;
- m_anno = new tchar[len];
- for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i];
+ m_annolen = rhs.m_annolen;
+ m_anno = new unsigned char[m_annolen];
+ memcpy(m_anno, rhs.m_anno, m_annolen);
}
else
- m_anno = NULL;
+ m_anno = NULL;
m_position = rhs.m_position;
return *this;
}
bool Bkmk::operator==(const Bkmk& rhs)
{
- return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0);
+ return (m_position == rhs.m_position && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0);
+}
+
+void Bkmk::setAnno(unsigned char* t, unsigned short len)
+{
+ if (m_anno != NULL)
+ {
+ delete [] m_anno;
+ m_anno = NULL;
+ }
+ if (t != NULL)
+ {
+ m_annolen = len;
+ m_anno = new unsigned char[m_annolen];
+ memcpy(m_anno, t, m_annolen);
+ }
+ else
+ {
+ m_annolen = sizeof(tchar);
+ m_anno = new unsigned char[m_annolen];
+ *((tchar*)m_anno) = 0;
+ }
}
void Bkmk::setAnno(tchar* t)
{
if (m_anno != NULL)
{
- delete [] m_anno;
- m_anno = NULL;
+ delete [] m_anno;
+ m_anno = NULL;
}
if (t != NULL)
{
- int len = ustrlen(t)+1;
- m_anno = new tchar[len];
- for (int i = 0; i < len; i++) m_anno[i] = t[i];
+ unsigned short len = ustrlen(t)+1;
+ m_annolen = sizeof(tchar)*len;
+ m_anno = new unsigned char[m_annolen];
+ memcpy(m_anno, t, m_annolen);
}
else
- m_anno = NULL;
+ {
+ m_annolen = sizeof(tchar);
+ m_anno = new unsigned char[m_annolen];
+ *((tchar*)m_anno) = 0;
+ }
}
-BkmkFile::BkmkFile(const char *fnm, bool w )
+BkmkFile::BkmkFile(const char *fnm, bool w = false)
:
wt(w), isUpgraded(false)
{
if (w)
{
- f = fopen(fnm, "wb");
+ f = fopen(fnm, "wb");
}
else
{
- f = fopen(fnm, "rb");
+ f = fopen(fnm, "rb");
}
}
@@ -110,55 +167,28 @@ BkmkFile::~BkmkFile()
if (f != NULL) fclose(f);
}
-void BkmkFile::write(tchar* nm, tchar* an, const unsigned int& pos)
+void BkmkFile::write(const Bkmk& b)
{
if (f != NULL)
{
- unsigned short ln = ustrlen(nm);
- fwrite(&ln,sizeof(ln),1,f);
- fwrite(nm,sizeof(tchar),ln,f);
- ln = ustrlen(an);
- fwrite(&ln,sizeof(ln),1,f);
- if (ln > 0) fwrite(an,sizeof(tchar),ln,f);
- fwrite(&pos,sizeof(pos),1,f);
+ fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f);
+ fwrite(b.m_name,1,b.m_namelen,f);
+ fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f);
+ fwrite(b.m_anno,1,b.m_annolen,f);
+ fwrite(&b.m_position,sizeof(b.m_position),1,f);
}
}
-void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); }
-
void BkmkFile::write(CList<Bkmk>& bl)
{
if (f != NULL)
{
- fwrite(&magic, sizeof(magic), 1, f);
- for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
- {
- write(*i);
- }
- }
-}
-
-Bkmk* BkmkFile::read()
-{
- Bkmk* b = NULL;
- if (f != NULL)
- {
- unsigned short ln;
- if (fread(&ln,sizeof(ln),1,f) == 1)
- {
- b = new Bkmk;
- b->m_name = new tchar[ln+1];
- fread(b->m_name,sizeof(tchar),ln,f);
- b->m_name[ln] = 0;
-
- fread(&ln,sizeof(ln),1,f);
- b->m_anno = new tchar[ln+1];
- if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f);
- b->m_anno[ln] = 0;
- fread(&b->m_position,sizeof(b->m_position),1,f);
- }
+ fwrite(&magic, sizeof(magic), 1, f);
+ for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
+ {
+ write(*i);
+ }
}
- return b;
}
CList<Bkmk>* BkmkFile::readall()
@@ -166,75 +196,127 @@ CList<Bkmk>* BkmkFile::readall()
CList<Bkmk>* bl = NULL;
if (f != NULL)
{
- unsigned long newmagic;
- fread(&newmagic, sizeof(newmagic), 1, f);
- if (newmagic != magic)
- {
- if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of OpieReader\ndid you upgrade from?", "0_4*", "Any other version") == 0)
- {
- fseek(f,0,SEEK_SET);
- bl = readall04();
- }
- else
- {
- fseek(f,0,SEEK_SET);
- bl = readall03();
- }
- isUpgraded = true;
- }
- else
- {
- bl = readall04();
- }
+ unsigned long newmagic;
+ fread(&newmagic, sizeof(newmagic), 1, f);
+ if ((newmagic & 0xffffff00) != (magic & 0xffffff00))
+ {
+ if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0)
+ {
+ fseek(f,0,SEEK_SET);
+ bl = readall00(&read05);
+ }
+ else
+ {
+ fseek(f,0,SEEK_SET);
+ bl = readall00(&read03);
+ }
+ isUpgraded = true;
+ }
+ else
+ {
+ switch(newmagic & 0xff)
+ {
+ case 6:
+ isUpgraded = false;
+ bl = readall00(read06);
+ qDebug("Correct version!");
+ break;
+ case 5:
+ isUpgraded = true;
+ bl = readall00(read05);
+ qDebug("Known version!");
+ break;
+ default:
+ qDebug("Unknown version!");
+ isUpgraded = true;
+ bl = readall00(read05);
+ }
+ }
}
return bl;
}
-CList<Bkmk>* BkmkFile::readall04()
+CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
{
CList<Bkmk>* bl = new CList<Bkmk>;
while (1)
{
- Bkmk* b = read();
- if (b == NULL) break;
- bl->push_back(*b);
- delete b;
+ Bkmk* b = (*readfn)(f);
+ if (b == NULL) break;
+ bl->push_back(*b);
+ delete b;
}
return bl;
}
-CList<Bkmk>* BkmkFile::readall03()
+Bkmk* BkmkFile::read03(FILE* f)
{
- CList<Bkmk>* bl = new CList<Bkmk>;
- while (1)
+ Bkmk* b = NULL;
+ if (f != NULL)
{
- Bkmk* b = read03();
- if (b == NULL) break;
- bl->push_back(*b);
- delete b;
+ unsigned short ln;
+ if (fread(&ln,sizeof(ln),1,f) == 1)
+ {
+ tchar* name = new tchar[ln+1];
+ fread(name,sizeof(tchar),ln,f);
+ name[ln] = 0;
+
+ ln = 0;
+ tchar* anno = new tchar[ln+1];
+ anno[ln] = 0;
+
+ unsigned int pos;
+ fread(&pos,sizeof(pos),1,f);
+ b = new Bkmk(name,anno,pos);
+ }
}
- return bl;
+ return b;
}
-Bkmk* BkmkFile::read03()
+Bkmk* BkmkFile::read05(FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
- unsigned short ln;
- if (fread(&ln,sizeof(ln),1,f) == 1)
- {
- b = new Bkmk;
- b->m_name = new tchar[ln+1];
- fread(b->m_name,sizeof(tchar),ln,f);
- b->m_name[ln] = 0;
+ unsigned short ln;
+ if (fread(&ln,sizeof(ln),1,f) == 1)
+ {
+ tchar* nm = new tchar[ln+1];
+ fread(nm,sizeof(tchar),ln,f);
+ nm[ln] = 0;
+ fread(&ln,sizeof(ln),1,f);
+ tchar* anno = new tchar[ln+1];
+ if (ln > 0) fread(anno,sizeof(tchar),ln,f);
+ anno[ln] = 0;
+ unsigned int pos;
+ fread(&pos,sizeof(pos),1,f);
+ b = new Bkmk(nm,anno,pos);
+ }
+ }
+ return b;
+}
- ln = 0;
- b->m_anno = new tchar[ln+1];
- b->m_anno[ln] = 0;
+Bkmk* BkmkFile::read06(FILE* f)
+{
+ Bkmk* b = NULL;
+ if (f != NULL)
+ {
+ unsigned short ln;
+ if (fread(&ln,sizeof(ln),1,f) == 1)
+ {
+ b = new Bkmk;
+ b->m_namelen = ln;
+ b->m_name = new unsigned char[b->m_namelen];
+ fread(b->m_name,1,b->m_namelen,f);
- fread(&b->m_position,sizeof(b->m_position),1,f);
- }
+ fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
+ if (b->m_annolen > 0)
+ {
+ b->m_anno = new unsigned char[b->m_annolen];
+ fread(b->m_anno,1,b->m_annolen,f);
+ }
+ fread(&(b->m_position),sizeof(b->m_position),1,f);
+ }
}
return b;
}
diff --git a/noncore/apps/opie-reader/Bkmks.h b/noncore/apps/opie-reader/Bkmks.h
index b38184a..ee528e4 100644
--- a/noncore/apps/opie-reader/Bkmks.h
+++ b/noncore/apps/opie-reader/Bkmks.h
@@ -2,6 +2,7 @@
#define __Bkmks_h
#include "config.h"
+#include "Filedata.h"
#include <stdio.h>
template<class T>
@@ -10,11 +11,16 @@ class CList;
class Bkmk
{
friend class BkmkFile;
- tchar* m_name;
- tchar* m_anno;
+ unsigned char* m_name;
+ unsigned short m_namelen;
+ unsigned char* m_anno;
+ unsigned short m_annolen;
unsigned int m_position;
+ void init(const void*, unsigned short, const void*, unsigned short, unsigned int);
public:
- Bkmk() : m_name(NULL), m_anno(NULL), m_position(0) {};
+ Bkmk() : m_name(NULL), m_namelen(0), m_anno(NULL), m_annolen(0), m_position(0) {};
+ Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p);
+ Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short _annolen, unsigned int _p);
Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p);
Bkmk(const Bkmk& rhs) : m_name(NULL), m_anno(NULL)
{
@@ -22,12 +28,24 @@ class Bkmk
}
~Bkmk();
unsigned int value() const { return m_position; }
- tchar *name() const { return m_name; }
- tchar *anno() const { return m_anno; }
+ void value(unsigned int _v) { m_position = _v; }
+ tchar *name() const { return (tchar*)m_name; }
+ tchar *anno() const { return (tchar*)m_anno; }
bool operator<(const Bkmk& rhs) { return (m_position < rhs.m_position); }
Bkmk& operator=(const Bkmk& rhs);
bool operator==(const Bkmk& rhs);
void setAnno(tchar* t);
+ void setAnno(unsigned char* t, unsigned short len);
+ unsigned char* filedata()
+ {
+ CFiledata fd(anno());
+ return m_anno+fd.length();
+ }
+ unsigned short filedatalen()
+ {
+ CFiledata fd(anno());
+ return m_annolen - fd.length();
+ }
};
class BkmkFile
@@ -37,11 +55,10 @@ class BkmkFile
bool isUpgraded;
static const unsigned long magic;
private:
- Bkmk* read();
- Bkmk* read03();
- CList<Bkmk>* readall03();
- CList<Bkmk>* readall04();
- void write(tchar* nm, tchar* an, const unsigned int& pos);
+ static Bkmk* read06(FILE*);
+ static Bkmk* read05(FILE*);
+ static Bkmk* read03(FILE*);
+ CList<Bkmk>* readall00(Bkmk*(*fn)(FILE*));
void write(const Bkmk& b);
public:
bool upgraded() { return isUpgraded; }
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp
index d4541ea..1123960 100644
--- a/noncore/apps/opie-reader/BuffDoc.cpp
+++ b/noncore/apps/opie-reader/BuffDoc.cpp
@@ -1,3 +1,5 @@
+#include "name.h"
+
#include "BuffDoc.h"
//#include <FL/fl_draw.h>
#include "config.h"
@@ -13,8 +15,8 @@ bool BuffDoc::hyperlink(unsigned int n)
lastispara = false;
if (exp != NULL)
{
- bRet = exp->hyperlink(n);
- lastsizes[0] = laststartline = exp->locate();
+ bRet = exp->hyperlink(n);
+ lastsizes[0] = laststartline = exp->locate();
}
return bRet;
}
@@ -30,22 +32,128 @@ void BuffDoc::locate(unsigned int n)
// qDebug("BuffDoc:Located");
}
-bool BuffDoc::getline(CDrawBuffer* buff, int w)
+#define NEWLINEBREAK
+#ifdef NEWLINEBREAK
+bool BuffDoc::getline(CDrawBuffer* buff, int wth)
{
+ bool moreleft = true;
+ bool margindone = false;
+ int w = wth-2*BORDER;
tchar ch = 32;
CStyle cs;
buff->empty();
if (exp == NULL)
{
-// (*buff)[0] = '\0';
- buff->empty();
- return false;
+ buff->empty();
+ buff->setEof();
+ return false;
+ }
+ int len = 0;
+ if (lastword.length() > 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(len);
+ lastispara = false;
+ while (1)
+ {
+ lastsizes[len] = exp->locate();
+ getch(ch, cs);
+ if (ch == UEOF)
+ {
+ lastword.empty();
+ if (len == 0)
+ {
+ buff->setEof();
+ moreleft = false;
+ }
+ laststartline = exp->locate();
+ break;
+ }
+ if (ch == 10)
+ {
+ lastword.empty();
+ lastispara = true;
+ laststartline = exp->locate();
+ break;
+ }
+ buff->addch(ch, cs);
+ len++;
+ if (!margindone)
+ {
+ w -= buff->leftMargin() + buff->rightMargin();
+ margindone = true;
+ }
+ if ((slen = buff->width(len)) > w)
+ {
+ if (ch == ' ' || len == 1)
+ {
+ lastword.empty();
+ laststartline = exp->locate();
+ break;
+ }
+ else // should do a backward search for spaces, first.
+ {
+ for (int i = len-1; i > 0; 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;
+ }
+ }
+ laststartline = lastsizes[len-1];
+ lastword.setright(*buff, len - 1);
+ buff->truncate(len-1);
+ buff->addch('-', cs);
+ for (int j = 0; j < lastword.length(); j++)
+ {
+ lastsizes[j] = lastsizes[j+len];
+ }
+ break;
+ }
+ }
+ }
+ (*buff)[len] = '\0';
+ buff->resize();
+ return moreleft;
+}
+#else
+bool BuffDoc::getline(CDrawBuffer* buff, int wth)
+{
+ bool margindone = false;
+ int w = wth-2*BORDER;
+ tchar ch = 32;
+ CStyle cs;
+ buff->empty();
+ if (exp == NULL)
+ {
+// (*buff)[0] = '\0';
+ buff->empty();
+ return false;
}
int len = 0, lastcheck = 0;
if (lastword.length() > 0)
{
*buff = lastword;
cs = lastword.laststyle();
+ w -= buff->leftMargin() + buff->rightMargin();
+ margindone = true;
}
else buff->empty();
// qDebug("Buff:%s Lastword:%s", (const char*)toQString(buff->data()), (const char*)toQString(lastword.data()));
@@ -53,18 +161,28 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
unsigned int slen = buff->width(len);
if (slen > w)
{
- for ( ; len > 0; len--)
- {
- if (buff->width(len) < w) break;
- }
+ for ( ; len > 1; len--)
+ {
+ if (buff->width(len) < w) break;
+ }
// lastword = buff->data() + len - 1;
laststartline = lastsizes[len-1];
- lastword.setright(*buff, len - 1);
for (int i = 0; i < buff->length(); i++) lastsizes[i] = lastsizes[i+len-1];
// (*buff)[len-1] = '-';
- buff->truncate(len-1);
- buff->addch('-', cs);
- (*buff)[len] = '\0';
+ if (len > 2)
+ {
+ lastword.setright(*buff, len - 1);
+ buff->truncate(len-1);
+ buff->addch('-', cs);
+ (*buff)[len] = '\0';
+ }
+
+ else
+ {
+ lastword.empty();
+ (*buff)[len] = '\0';
+ }
+ buff->resize();
return true;
}
if (lastispara)
@@ -77,6 +195,7 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
// (*buff)[len] = '\0';
buff->truncate(len);
laststartline = exp->locate();
+ buff->resize();
return true;
}
lastispara = false;
@@ -88,27 +207,40 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
getch(ch, cs);
while (ch != ' ' && ch != '\012' && ch != UEOF && len < 128)
{
- len++;
- buff->addch(ch,cs);
- allsizes[len] = exp->locate();
- getch(ch, cs);
+ len++;
+ buff->addch(ch,cs);
+ allsizes[len] = exp->locate();
+ getch(ch, cs);
}
(*buff)[len] = 0;
slen = buff->width(len);
len++;
buff->addch(' ', cs);
+ if (!margindone)
+ {
+ w -= buff->leftMargin() + buff->rightMargin();
+ margindone = true;
+ }
allsizes[len] = exp->locate();
if (slen < w && ch != ' ')
{
- lastcheck = len;
- break;
+ lastcheck = len;
+ break;
}
lastispara = (ch == '\012');
}
(*buff)[len] = '\0';
// lastword = buff->data()+lastcheck;
- lastword.setright(*buff, lastcheck);
+#ifdef WINDOWS
+ lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
+ {
+ int i;
+ for (i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
+ }
+#else
+ lastword.setright(*buff, (lastcheck > 0) ? lastcheck : 1);
for (int i = 0; i < lastword.length(); i++) lastsizes[i] = allsizes[i+lastcheck];
+#endif
if (lastcheck > 0)
{
laststartline = allsizes[lastcheck];
@@ -122,28 +254,37 @@ bool BuffDoc::getline(CDrawBuffer* buff, int w)
buff->truncate(lastcheck);
}
// buff->frig();
- return (ch != UEOF);
+ buff->resize();
+ if (ch == UEOF && buff->length() == 0)
+ {
+ buff->setEof();
+ return false;
+ }
+ return true;
}
+#endif
-bool BuffDoc::getline(CDrawBuffer* buff, int w, int cw)
+bool BuffDoc::getline(CDrawBuffer* buff, int wth, int cw)
{
+ int w = wth-2*BORDER;
buff->empty();
if (exp == NULL)
{
- return false;
+ return false;
}
tchar ch;
CStyle cs;
int i = 0;
while (i*cw < w)
{
- getch(ch, cs);
- if (ch == '\12' || ch == UEOF) break;
- buff->addch(ch,cs);
- i++;
+ getch(ch, cs);
+ if (ch == '\12' || ch == UEOF) break;
+ buff->addch(ch,cs);
+ i++;
}
buff->truncate(i);
laststartline = exp->locate();
+ buff->resize();
return (ch != UEOF);
}
@@ -164,53 +305,44 @@ int BuffDoc::openfile(QWidget* _parent, const char *src)
int ret = exp->openfile(src);
if (ret == -1)
{
- delete exp;
- exp = NULL;
- return ret;
+ delete exp;
+ exp = NULL;
+ return ret;
}
if (ret == -2)
{
- delete exp;
- exp = new ztxt;
- ret = exp->openfile(src);
+ delete exp;
+ exp = new ztxt;
+ ret = exp->openfile(src);
}
if (ret != 0)
{
- delete exp;
- exp = new CPlucker;
- ret = exp->openfile(src);
+ delete exp;
+ exp = new CPlucker;
+ ret = exp->openfile(src);
}
-#ifndef SMALL
if (ret != 0)
{
- delete exp;
- qDebug("Trying ppms");
- exp = new ppm_expander;
- ret = exp->openfile(src);
+ delete exp;
+ qDebug("Trying ppms");
+ exp = new ppm_expander;
+ ret = exp->openfile(src);
}
-
if (ret != 0)
{
- delete exp;
- exp = new Text;
-// qDebug("Trying text");
- ret = exp->openfile(src);
+ delete exp;
+ exp = new Text;
+// qDebug("Trying text");
+ ret = exp->openfile(src);
}
-#else
- if (ret != 0)
- {
- delete exp;
- exp = new Text;
- ret = exp->openfile(src);
- }
-#endif
+
if (ret != 0)
{
- delete exp;
- QMessageBox::information(_parent, "OpieReader", "Unknown file compression type","Try another file");
- return ret;
+ delete exp;
+ QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file");
+ return ret;
}
// qDebug("Doing final open:%x:%x",exp,filt);
diff --git a/noncore/apps/opie-reader/BuffDoc.h b/noncore/apps/opie-reader/BuffDoc.h
index 1aac817..78d8457 100644
--- a/noncore/apps/opie-reader/BuffDoc.h
+++ b/noncore/apps/opie-reader/BuffDoc.h
@@ -19,6 +19,27 @@ class BuffDoc
CExpander* exp;
CFilterChain* filt;
public:
+ 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);
+ }
+ }
+ void suspend() { if (exp != NULL) exp->suspend(); }
+ void unsuspend() { if (exp != NULL) exp->unsuspend(); }
~BuffDoc()
{
delete filt;
@@ -61,10 +82,15 @@ class BuffDoc
else
ch = UEOF;
}
+ QPixmap* 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(); }
bool hyperlink(unsigned int n);
+ size_t getHome() { return ((exp != NULL) ? exp->getHome() : 0); }
void locate(unsigned int n);
bool getline(CDrawBuffer* buff, int w);
bool getline(CDrawBuffer* buff, int w, int cw);
@@ -79,6 +105,10 @@ class BuffDoc
laststartline = exp->locate();
return i;
}
+ void saveposn(size_t posn) { exp->saveposn(posn); }
+ bool forward(size_t& loc) { return exp->forward(loc); }
+ bool back(size_t& loc) { return exp->back(loc); }
+ bool hasnavigation() { return exp->hasnavigation(); }
};
#endif
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp
index 0780a88..526b25f 100644
--- a/noncore/apps/opie-reader/CBuffer.cpp
+++ b/noncore/apps/opie-reader/CBuffer.cpp
@@ -11,7 +11,7 @@ CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms)
return *this;
}
-CBufferBase::CBufferBase(size_t ms, size_t n) : len(n), membersize(ms)
+CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms)
{
buffer = new unsigned char[len*membersize];
memset(buffer, 0, len*membersize);
@@ -31,7 +31,7 @@ void* CBufferBase::operator[](int i)
return buffer+i*membersize;
}
-size_t CBufferBase::bstrlen(unsigned char* _buffer)
+size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL)
{
if (_buffer == NULL) _buffer = buffer;
unsigned char* zero = new unsigned char[membersize];
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp
index 892456f..ca220e6 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.cpp
+++ b/noncore/apps/opie-reader/CDrawBuffer.cpp
@@ -1,19 +1,25 @@
-
#include "CDrawBuffer.h"
#include "FontControl.h"
#include <qfontmetrics.h>
#include <qpainter.h>
+#include <qpixmap.h>
+#include "opie.h"
+
+CDrawBuffer::~CDrawBuffer()
+{
+ while (!segs.isEmpty()) segs.erase(0);
+}
void CDrawBuffer::setright(CDrawBuffer& rhs, int f)
{
int i;
-// qDebug("Trying 1:%d:%s", f, (const char*)toQString(rhs.data()));
len = rhs.len;
- m_maxstyle = rhs.m_maxstyle;
- m_ascent = rhs.m_ascent;
- m_descent = rhs.m_descent;
- m_lineSpacing = rhs.m_lineSpacing;
- while (!segs.isEmpty()) segs.erase(0);
+ fc = rhs.fc;
+ m_maxstyle = 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;
@@ -22,13 +28,15 @@ void CDrawBuffer::setright(CDrawBuffer& rhs, int 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;
-// qDebug("Tried 1");
}
CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
@@ -40,7 +48,11 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
m_ascent = rhs.m_ascent;
m_descent = rhs.m_descent;
m_lineSpacing = rhs.m_lineSpacing;
- while (!segs.isEmpty()) segs.erase(0);
+ m_lineExtraSpacing = rhs.m_lineExtraSpacing;
+ while (!segs.isEmpty())
+ {
+ segs.erase(0);
+ }
for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++)
{
segs.push_back(*iter);
@@ -55,7 +67,10 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs)
CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp)
{
int i;
- while (!segs.isEmpty()) segs.erase(0);
+ 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';
@@ -67,33 +82,24 @@ void CDrawBuffer::empty()
{
len = 0;
(*this)[0] = 0;
- while (!segs.isEmpty()) segs.erase(0);
+ while (!segs.isEmpty())
+ {
+ segs.erase(0);
+ }
segs.push_back(textsegment(0,CStyle()));
- m_maxstyle = m_ascent = m_descent = m_lineSpacing = 0;
+ m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
+ m_bEof = false;
}
void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/)
{
if (len == 0)
{
- int thissize = fc->getsize(_style);
- m_maxstyle = thissize;
- m_ascent = fc->ascent(_style);
- m_descent = fc->descent(_style);
- m_lineSpacing = fc->lineSpacing(_style);
segs.first().start = 0;
segs.first().style = _style;
}
else if (_style != segs.last().style)
{
- int thissize = fc->getsize(_style);
- if (thissize > m_maxstyle)
- {
- m_maxstyle = thissize;
- m_ascent = fc->ascent(_style);
- m_descent = fc->descent(_style);
- m_lineSpacing = fc->lineSpacing(_style);
- }
segs.push_back(textsegment(len, _style));
}
(*this)[len++] = ch;
@@ -120,52 +126,119 @@ int CDrawBuffer::width(int numchars)
end = numchars;
}
CStyle currentstyle = textstart->style;
- QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
- QString str = text.mid(textstart->start, end-textstart->start);
- QFontMetrics fm(f);
- currentx += fm.width(str);
+ if (currentstyle.isPicture())
+ {
+ 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("courier") : 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);
+ currentx += fm.width(str);
+ }
+ }
textstart = textend;
}
while (textend != segs.end() && end != numchars);
return currentx;
}
+int CDrawBuffer::leftMargin()
+{
+ return (segs.begin()->style.getLeftMargin()*fc->getsize(segs.begin()->style))/6;
+}
+
+int CDrawBuffer::rightMargin()
+{
+ return (segs.begin()->style.getRightMargin()*fc->getsize(segs.begin()->style))/6;
+}
+
+int CDrawBuffer::offset(int scwidth)
+{
+ int currentx = BORDER;
+ switch(segs.begin()->style.getJustify())
+ {
+ case m_AlignRight:
+ {
+ currentx = scwidth - BORDER - rightMargin() - width();
+ }
+ break;
+ case m_AlignCentre:
+ {
+ currentx = (
+ scwidth +
+ leftMargin() - rightMargin()
+ - width())/2;
+ }
+ break;
+ case m_AlignJustify:
+ case m_AlignLeft:
+ currentx = BORDER + leftMargin();
+ break;
+ }
+ return currentx;
+}
+
void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth)
{
- int currentx = 0;
+ int currentx = offset(scwidth);
QString text = toQString(data());
CList<textsegment>::iterator textstart = segs.begin();
+/*
StyleType align = textstart->style.getJustify();
switch (align)
{
case CStyle::m_AlignRight:
{
-// int linelength = width();
- currentx = scwidth - width();
+ currentx = scwidth - width() - 2*BORDER;
}
break;
case CStyle::m_AlignCentre:
{
-// int linelength = width();
- currentx = (scwidth - width())/2;
+ currentx = (scwidth - width())/2 - BORDER;
}
break;
case CStyle::m_AlignJustify:
case CStyle::m_AlignLeft:
break;
}
+*/
CList<textsegment>::iterator textend = textstart;
do
{
textend++;
int end = (textend != segs.end()) ? textend->start : length();
CStyle currentstyle = textstart->style;
- QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
+ QFont f((currentstyle.isMono() && fc->hasCourier()) ? QString("courier") : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) );
+// f.setUnderline(currentstyle.isUnderline());
+// if (currentstyle.isUnderline()) qDebug("UNDERLINE");
_p->setFont(f);
QString str = text.mid(textstart->start, end-textstart->start);
- _p->setPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()));
+#ifdef OPIE
+ _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/100));
+#else
+ _p->setPen(QPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue()), fc->getsize(currentstyle)/10));
+#endif
if (_bMono)
{
+ if (currentstyle.isUnderline())
+ {
+ _p->drawLine( currentx, _y, currentx + str.length()*_charWidth, _y);
+ }
+ if (currentstyle.isStrikethru())
+ {
+ int ascent = fc->ascent(currentstyle)/3;
+ _p->drawLine( currentx, _y-ascent, currentx + str.length()*_charWidth, _y-ascent);
+ }
for (int i = 0; i < str.length(); i++)
{
_p->drawText( currentx + i*_charWidth, _y, QString(str[i]));
@@ -174,13 +247,57 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int
}
else
{
- _p->drawText( currentx, _y, str);
- QFontMetrics fm(f);
- currentx += fm.width(str);
+ if (currentstyle.isPicture())
+ {
+ int ascent = fc->ascent(currentstyle)/2;
+ int yoffset = currentstyle.getPicture()->height()/2 + ascent;
+ _p->drawPixmap( currentx, _y-yoffset, *(currentstyle.getPicture()));
+ currentx += currentstyle.getPicture()->width();
+ }
+ else
+ {
+ if (currentstyle.isMono() && !fc->hasCourier())
+ {
+ int cw = (7*fc->getsize(currentstyle))/10;
+ int w = cw*(end-textstart->start);
+ if (currentstyle.isUnderline())
+ {
+ _p->drawLine( currentx, _y, currentx + w, _y);
+ }
+ if (currentstyle.isStrikethru())
+ {
+ int ascent = fc->ascent(currentstyle)/3;
+ _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
+ }
+ QString str = text.mid(textstart->start, end-textstart->start);
+
+ for (int i = 0; i < str.length(); i++)
+ {
+ _p->drawText( currentx, _y, QString(str[i]));
+ currentx += cw;
+ }
+ }
+ else
+ {
+ QFontMetrics fm(f);
+ int w = fm.width(str);
+ if (currentstyle.isUnderline())
+ {
+ _p->drawLine( currentx, _y, currentx + w, _y);
+ }
+ if (currentstyle.isStrikethru())
+ {
+ int ascent = fc->ascent(currentstyle)/3;
+ _p->drawLine( currentx, _y-ascent, currentx + w, _y-ascent);
+ }
+ _p->drawText( currentx, _y, str);
+ currentx += w;
+ }
+ }
}
textstart = textend;
}
- while (textend != segs.end());
+ while (textend != segs.end() && textstart->start < length()-1);
}
CStyle CDrawBuffer::laststyle()
@@ -188,7 +305,7 @@ CStyle CDrawBuffer::laststyle()
return segs.last().style;
}
-bool CDrawBuffer::isLink(int numchars, size_t& tgt)
+linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt)
{
int end = 0;
CStyle currentstyle;
@@ -198,14 +315,65 @@ bool CDrawBuffer::isLink(int numchars, size_t& tgt)
{
textend++;
end = (textend != segs.end()) ? textend->start : length();
- if (numchars >= 0 && end > numchars)
- {
- end = numchars;
- }
currentstyle = textstart->style;
+/*
+ if (currentstyle.isPicture()) qDebug("Passed thru picture");
+ if (currentstyle.getLink()) qDebug("Passed thru link");
+ qDebug("islink:%d - %d", numchars, end);
+*/
textstart = textend;
}
- while (textend != segs.end() && end != numchars);
- tgt = currentstyle.getData();
- return currentstyle.getLink();
+ while (textend != segs.end() && end <= numchars);
+// if (currentstyle.isPicture()) qDebug("Clicked on picture");
+ if (currentstyle.getPictureLink())
+ {
+ tgt = currentstyle.getPictureLinkData();
+ return ePicture;
+ }
+ if (currentstyle.getLink())
+ {
+ tgt = currentstyle.getData();
+ return eLink;
+ }
+ return eNone;
+}
+
+void CDrawBuffer::resize()
+{
+ int i;
+ m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0;
+ for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= length(); )
+ {
+ CList<textsegment>::iterator next = iter;
+ iter++;
+ int st = next->start;
+ if (st < 0) st = 0;
+
+ CStyle _style = next->style;
+
+ int linespacing, ascent, descent, extra;
+
+ ascent = fc->ascent(_style);
+ descent = fc->descent(_style);
+ linespacing = fc->lineSpacing(_style);
+ extra = linespacing - ascent - descent;
+ if (_style.isPicture())
+ {
+ descent = (_style.getPicture()->height()-ascent)/2;
+ ascent = (_style.getPicture()->height()+ascent)/2;
+ }
+/*
+ else if (fc != NULL)
+ {
+ ascent = fc->ascent(_style);
+ descent = fc->descent(_style);
+ linespacing = fc->lineSpacing(_style);
+ extra = linespacing - ascent - descent;
+ }
+*/
+ if (ascent > m_ascent) m_ascent = ascent;
+ if (descent > m_descent) m_descent = descent;
+ if (extra > m_lineExtraSpacing) m_lineExtraSpacing = extra;
+ m_lineSpacing = m_ascent+m_descent+m_lineExtraSpacing;
+ }
}
diff --git a/noncore/apps/opie-reader/CDrawBuffer.h b/noncore/apps/opie-reader/CDrawBuffer.h
index 4d3696e..0d8968c 100644
--- a/noncore/apps/opie-reader/CDrawBuffer.h
+++ b/noncore/apps/opie-reader/CDrawBuffer.h
@@ -7,11 +7,18 @@
class QPainter;
+enum linkType
+{
+ eNone,
+ eLink,
+ ePicture
+};
+
struct textsegment
{
int start;
CStyle style;
- textsegment(int _start, CStyle _style)
+ textsegment(int _start, const CStyle& _style)
:
start(_start), style(_style)
{}
@@ -24,14 +31,23 @@ class CDrawBuffer : public CBuffer
CList<textsegment> segs;
int len;
FontControl* fc;
- int m_maxstyle, m_ascent, m_descent, m_lineSpacing;
+ int m_maxstyle, m_ascent, m_descent, m_lineSpacing, m_lineExtraSpacing;
+ bool m_bEof;
+ CDrawBuffer(const CDrawBuffer&);
+ CDrawBuffer& operator=(const tchar*sztmp);
public:
+ int leftMargin();
+ int rightMargin();
+ void setEof() { m_bEof = true; }
+ bool eof() { return m_bEof; }
+ CDrawBuffer& operator=(CDrawBuffer&);
CDrawBuffer(FontControl* _fs = NULL)
:
fc(_fs)
{
empty();
}
+ ~CDrawBuffer();
/*
CDrawBuffer()
:
@@ -41,9 +57,8 @@ class CDrawBuffer : public CBuffer
}
*/
int width(int numchars = -1);
+ int offset(int);
void render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scw);
- CDrawBuffer& operator=(const tchar*sztmp);
- CDrawBuffer& operator=(CDrawBuffer&);
void empty();
void addch(tchar ch, CStyle _style);
void truncate(int);
@@ -52,8 +67,10 @@ class CDrawBuffer : public CBuffer
int ascent() { return m_ascent; }
int descent() { return m_descent; }
int lineSpacing() { return m_lineSpacing; }
+ int lineExtraSpacing() { return m_lineExtraSpacing; }
// void frig();
- bool isLink(int numchars, size_t& tgt);
+ linkType getLinkType(int numchars, size_t& tgt);
+ void resize();
};
#endif
diff --git a/noncore/apps/opie-reader/CExpander.h b/noncore/apps/opie-reader/CExpander.h
index b1147a6..c281398 100644
--- a/noncore/apps/opie-reader/CExpander.h
+++ b/noncore/apps/opie-reader/CExpander.h
@@ -1,10 +1,16 @@
#ifndef __CExpander_h
#define __CExpander_h
+#include <unistd.h>
+#include <stdio.h>
+#include <time.h>
+#include <qmessagebox.h>
#include "config.h"
#include "StyleConsts.h"
#include "Markups.h"
+#include "name.h"
+class QPixmap;
class Bkmk;
template<class T>
@@ -18,10 +24,26 @@ class CCharacterSource
class CExpander
{
+ protected:
+ size_t m_homepos;
+ bool m_continuous;
+ char* fname;
+ bool bSuspended;
+ size_t suspos;
+ time_t sustime;
public:
- CExpander() {};
- virtual ~CExpander() {};
- virtual int openfile(const char *src) = 0;
+ virtual void suspend() = 0;
+ virtual void unsuspend() = 0;
+ size_t getHome() { return m_homepos; }
+ CExpander() : m_homepos(0), fname(NULL) {};
+ virtual ~CExpander() { if (fname != NULL) delete [] fname; };
+ int openfile(const char *src)
+ {
+ bSuspended = false;
+ fname = strdup(src);
+ return OpenFile(src);
+ }
+ virtual int OpenFile(const char *src) = 0;
virtual unsigned int locate() = 0;
virtual void locate(unsigned int n) = 0;
virtual bool hasrandomaccess() = 0;
@@ -39,5 +61,64 @@ class CExpander
return true;
}
virtual MarkupType PreferredMarkup() = 0;
+ virtual void saveposn(size_t posn) {}
+ virtual bool forward(size_t& loc) {}
+ virtual bool back(size_t& loc) {}
+ virtual bool hasnavigation() { return false; }
+ virtual unsigned long startSection()
+ {
+ return 0;
+ }
+ virtual unsigned long endSection()
+ {
+ unsigned long file, text;
+ sizes(file, text);
+ return text;
+ }
+ virtual QPixmap* getPicture(unsigned long tgt) { return NULL; }
+ void setContinuous(bool _b) { m_continuous = _b; }
+
+ virtual void suspend(FILE*& fin)
+ {
+ bSuspended = true;
+ suspos = ftell(fin);
+ fclose(fin);
+ fin = NULL;
+ sustime = time(NULL);
+ }
+ virtual void unsuspend(FILE*& fin)
+ {
+ if (bSuspended)
+ {
+ bSuspended = false;
+ int delay = time(NULL) - sustime;
+ if (delay < 10) sleep(10-delay);
+ fin = fopen(fname, "rb");
+ for (int i = 0; fin == NULL && i < 5; i++)
+ {
+ sleep(5);
+ fin = fopen(fname, "rb");
+ }
+ if (fin == NULL)
+ {
+ QMessageBox::warning(NULL, PROGNAME, "Couldn't reopen file");
+ exit(0);
+ }
+ suspos = fseek(fin, suspos, SEEK_SET);
+ }
+ }
+ virtual void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
+ {
+ len = srclen;
+ data = new unsigned char[len];
+ memcpy(data, src, len);
+ }
+ virtual void putSaveData(unsigned char*& src, unsigned short& srclen)
+ {
+ if (srclen != 0)
+ {
+ qDebug("Don't know what to do with non-zero save data");
+ }
+ }
};
#endif
diff --git a/noncore/apps/opie-reader/CFilter.cpp b/noncore/apps/opie-reader/CFilter.cpp
index c17cf61..d5e3116 100644
--- a/noncore/apps/opie-reader/CFilter.cpp
+++ b/noncore/apps/opie-reader/CFilter.cpp
@@ -532,7 +532,7 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty)
parent->getch(ch, dummy);
break;
case 'c':
- if (currentstyle.getJustify() == CStyle::m_AlignCentre)
+ if (currentstyle.getJustify() == m_AlignCentre)
{
currentstyle.setLeftJustify();
}
@@ -543,7 +543,7 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty)
parent->getch(ch, dummy);
break;
case 'r':
- if (currentstyle.getJustify() == CStyle::m_AlignRight)
+ if (currentstyle.getJustify() == m_AlignRight)
{
currentstyle.setLeftJustify();
}
@@ -559,3 +559,126 @@ void PeanutFormatter::getch(tchar& ch, CStyle& sty)
}
sty = currentstyle;
}
+
+void OnePara::getch(tchar& ch, CStyle& sty)
+{
+ parent->getch(ch, sty);
+ if (m_lastchar == 10)
+ {
+ while (ch == 10) parent->getch(ch, sty);
+ }
+ m_lastchar = ch;
+}
+
+#ifdef REPALM
+void repalm::getch(tchar& ch, CStyle& sty)
+{
+ parent->getch(ch, sty);
+ switch (ch)
+ {
+ case 0x80:
+ ch = 0x20ac;
+ break;
+ case 0x82:
+ ch = 0x201a;
+ break;
+ case 0x83:
+ ch = 0x0192;
+ break;
+ case 0x84:
+ ch = 0x201e;
+ break;
+ case 0x85:
+ ch = 0x2026;
+ break;
+ case 0x86:
+ ch = 0x2020;
+ break;
+ case 0x87:
+ ch = 0x2021;
+ break;
+ case 0x88:
+ ch = 0x02c6;
+ break;
+ case 0x89:
+ ch = 0x2030;
+ break;
+ case 0x8a:
+ ch = 0x0160;
+ break;
+ case 0x8b:
+ ch = 0x2039;
+ break;
+ case 0x8c:
+ ch = 0x0152;
+ break;
+/*
+ case 0x8e:
+ ch = 0x017d;
+ break;
+*/
+ case 0x91:
+ ch = 0x2018;
+ break;
+ case 0x92:
+ ch = 0x2019;
+ break;
+ case 0x93:
+ ch = 0x201c;
+ break;
+ case 0x94:
+ ch = 0x201d;
+ break;
+ case 0x95:
+ ch = 0x2022;
+ break;
+ case 0x96:
+ ch = 0x2013;
+ break;
+ case 0x97:
+ ch = 0x2014;
+ break;
+ case 0x98:
+ ch = 0x02dc;
+ break;
+ case 0x99:
+ ch = 0x2122;
+ break;
+ case 0x9a:
+ ch = 0x0161;
+ break;
+ case 0x9b:
+ ch = 0x203a;
+ break;
+ case 0x9c:
+ ch = 0x0153;
+ break;
+ case 0x9e:
+ ch = 0x017e;
+ break;
+ case 0x9f:
+ ch = 0x0178;
+ break;
+ case 0x18:
+ ch = 0x2026;
+ break;
+ case 0x19:
+ ch = 0x2007;
+ break;
+ case 0x8d:
+ ch = 0x2662;
+ break;
+ case 0x8e:
+ ch = 0x2663;
+ break;
+ case 0x8f:
+ ch = 0x2661;
+ break;
+ case 0x90:
+ ch = 0x2660;
+ break;
+ default:
+ break;
+ }
+}
+#endif
diff --git a/noncore/apps/opie-reader/CFilter.h b/noncore/apps/opie-reader/CFilter.h
index 8cfd7eb..2d0c30f 100644
--- a/noncore/apps/opie-reader/CFilter.h
+++ b/noncore/apps/opie-reader/CFilter.h
@@ -266,4 +266,22 @@ class PeanutFormatter : public CFilter
virtual ~PeanutFormatter() {}
virtual void getch(tchar& ch, CStyle& sty);
};
+
+class OnePara : public CFilter
+{
+ tchar m_lastchar;
+ public:
+ OnePara() : m_lastchar(0) {}
+ virtual ~OnePara() {}
+ virtual void getch(tchar& ch, CStyle& sty);
+};
+
+#ifdef REPALM
+class repalm : public CFilter
+{
+ public:
+ virtual ~repalm() {}
+ virtual void getch(tchar& ch, CStyle& sty);
+};
+#endif
#endif
diff --git a/noncore/apps/opie-reader/Filedata.h b/noncore/apps/opie-reader/Filedata.h
new file mode 100644
index 0000000..f920238
--- a/dev/null
+++ b/noncore/apps/opie-reader/Filedata.h
@@ -0,0 +1,51 @@
+#ifndef __FILEDATA_H
+#define __FILEDATA_H
+
+#include <time.h>
+
+class CFiledata
+{
+ unsigned char* data;
+ bool m_own;
+ public:
+ CFiledata(tchar* d)
+ {
+ data = (unsigned char*)d;
+ m_own = false;
+ }
+ CFiledata(time_t dt, tchar* nm)
+ {
+ int nlen = ustrlen(nm)+1;
+ data = new unsigned char[sizeof(time_t)+sizeof(tchar)*nlen];
+ *((time_t *)data) = dt;
+ memcpy(data+sizeof(time_t), nm, sizeof(tchar)*nlen);
+ m_own = true;
+ }
+ ~CFiledata()
+ {
+ if (m_own && data != NULL)
+ {
+ delete [] data;
+ qDebug("~Filedata: deleting");
+ }
+ else
+ {
+ qDebug("~Filedata: not deleting");
+ }
+ }
+ tchar* name() const { return (tchar*)(data+sizeof(time_t)); }
+ time_t date() { return *((time_t *)data); }
+ void setdate(time_t _t) { *((time_t *)data) = _t; }
+ unsigned char* content() { return data; }
+ size_t length() const { return sizeof(time_t)+sizeof(tchar)*(ustrlen(name())+1); }
+ bool operator==(const CFiledata& rhs)
+ {
+ return ((length() == rhs.length()) && (memcmp(data, rhs.data, length()) == 0));
+ }
+ bool samename(const CFiledata& rhs)
+ {
+ return (ustrcmp((tchar *)(data+sizeof(time_t)),(tchar *)(rhs.data+sizeof(time_t))) == 0);
+ }
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/FontControl.cpp b/noncore/apps/opie-reader/FontControl.cpp
new file mode 100644
index 0000000..f0ed98b
--- a/dev/null
+++ b/noncore/apps/opie-reader/FontControl.cpp
@@ -0,0 +1,37 @@
+#include "opie.h"
+#include "FontControl.h"
+
+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++)
+ {
+#ifdef OPIE
+ 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++;
+ }
+ m_size = best;
+ }
+ return true;
+}
diff --git a/noncore/apps/opie-reader/FontControl.h b/noncore/apps/opie-reader/FontControl.h
index d427680..02049d0 100644
--- a/noncore/apps/opie-reader/FontControl.h
+++ b/noncore/apps/opie-reader/FontControl.h
@@ -11,10 +11,11 @@ class FontControl
int m_size;
QString m_fontname;
int m_maxsize;
+ bool m_hasCourier;
public:
FontControl(QString n = "helvetica", int size = 10)
:
- m_fontsizes(NULL)
+ m_fontsizes(NULL), m_hasCourier(false)
{
ChangeFont(n, size);
}
@@ -22,11 +23,22 @@ class FontControl
{
if (m_fontsizes != NULL) delete [] m_fontsizes;
}
+ void hasCourier(bool _b) { m_hasCourier = _b; }
+ bool hasCourier() { return m_hasCourier; }
QString name() { return m_fontname; }
int currentsize() { return m_fontsizes[m_size]; }
int getsize(CStyle size)
{
- return m_fontsizes[m_size+size.getFontSize()];
+ int tgt = m_size+size.getFontSize();
+ if (tgt < 0)
+ {
+ tgt = 0;
+ }
+ if (tgt >= m_maxsize)
+ {
+ tgt = m_maxsize - 1;
+ }
+ return m_fontsizes[tgt];
}
int ascent()
{
@@ -86,36 +98,7 @@ class FontControl
{
return ChangeFont(n, currentsize());
}
- bool 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++)
- {
- m_fontsizes[i] = (*it);
- if (abs(tgt-m_fontsizes[i]) < abs(tgt-m_fontsizes[best]))
- {
- best = i;
- }
- i++;
- }
- m_size = best;
- }
- return true;
- }
+ bool ChangeFont(QString& n, int tgt);
};
#endif
diff --git a/noncore/apps/opie-reader/GraphicWin.h b/noncore/apps/opie-reader/GraphicWin.h
new file mode 100644
index 0000000..31811d2
--- a/dev/null
+++ b/noncore/apps/opie-reader/GraphicWin.h
@@ -0,0 +1,65 @@
+#ifndef __GRAPHICWIN_H
+#define __GRAPHICWIN_H
+
+#include <qscrollview.h>
+#include <qpixmap.h>
+#include <qpushbutton.h>
+#include <qlayout.h>
+
+class GraphicScroll : public QScrollView
+{
+ Q_OBJECT
+ QWidget* m_picture;
+ protected:
+ void hideEvent( QHideEvent * p)
+ {
+ m_picture->setFixedSize(1,1);
+ }
+ public:
+ GraphicScroll( QWidget *parent=0, const char *name=0, WFlags f = 0)
+ : QScrollView(parent, name, f)
+ {
+ m_picture = new QWidget(viewport());
+ addChild(m_picture);
+ }
+ void setPixmap(QPixmap& pm)
+ {
+ m_picture->setFixedSize(pm.size());
+ m_picture->setBackgroundPixmap(pm);
+ }
+/*
+ private slots:
+ void graphicClose() { emit Close(); }
+ signals:
+ void Close();
+*/
+
+};
+
+
+class GraphicWin : public QWidget
+{
+ Q_OBJECT
+
+ GraphicScroll* m_scroll;
+ signals:
+ void Closed();
+ private slots:
+ void slotClosed() { emit Closed(); }
+
+ public:
+
+ void setPixmap(QPixmap& pm) { m_scroll->setPixmap(pm); }
+ GraphicWin( QWidget *parent=0, const char *name=0, WFlags f = 0)
+ : QWidget(parent, name, f)
+ {
+ QVBoxLayout* grid = new QVBoxLayout(this);
+ m_scroll = new GraphicScroll(this);
+ QPushButton* exitButton = new QPushButton("Close", this);
+ connect(exitButton, SIGNAL( released() ), this, SLOT( slotClosed() ) );
+ grid->addWidget(m_scroll,1);
+ grid->addWidget(exitButton);
+ }
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/Navigation.cpp b/noncore/apps/opie-reader/Navigation.cpp
new file mode 100644
index 0000000..7b392ba
--- a/dev/null
+++ b/noncore/apps/opie-reader/Navigation.cpp
@@ -0,0 +1,98 @@
+#include "Navigation.h"
+
+void CNavigation::saveposn(size_t posn)
+{
+// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
+ historycurrent = historyend = (historycurrent+1)%NAVIGATION_HISTORY_SIZE;
+ history[historycurrent] = posn;
+ if (historystart == historyend) historystart = (historystart+1)%NAVIGATION_HISTORY_SIZE;
+// qDebug("Saved:%u [%u,%u,%u]", posn, historystart, historycurrent, historyend);
+}
+
+bool CNavigation::forward(size_t& loc)
+{
+ if (historycurrent != historyend)
+ {
+ historycurrent = (historycurrent + 1)%NAVIGATION_HISTORY_SIZE;
+ loc = history[historycurrent];
+// qDebug("Forward:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+bool CNavigation::back(size_t& loc)
+{
+ if (historyend != historystart)
+ {
+// qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
+ if (historycurrent == historyend && history[historycurrent] != loc)
+ {
+ historyend = (historyend+1) % NAVIGATION_HISTORY_SIZE;
+ history[historyend] = loc;
+ }
+ else
+ {
+ size_t sv = historycurrent;
+ historycurrent = (historycurrent + NAVIGATION_HISTORY_SIZE - 1) % NAVIGATION_HISTORY_SIZE;
+ if (historycurrent == historystart)
+ {
+ historycurrent = sv;
+ return false;
+ }
+ }
+ loc = history[historycurrent];
+// qDebug("Back:%u [%u,%u,%u]", loc, historystart, historycurrent, historyend);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+#include <stdio.h>
+
+void CNavigation::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
+{
+ len = srclen+sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
+ data = new unsigned char[len];
+ unsigned char* p = data;
+ memcpy(p, src, srclen);
+ p += srclen;
+ memcpy(p, &historystart, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, &historyend, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, &historycurrent, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(p, history, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
+ printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
+ for (int i = historystart; i <= historyend; i++)
+ printf("<%u> ", history[i]);
+ printf("\n");
+}
+
+void CNavigation::putSaveData(unsigned char*& src, unsigned short& srclen)
+{
+ if (srclen >= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE))
+ {
+ unsigned char* p = src;
+ memcpy(&historystart, p, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(&historyend, p, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(&historycurrent, p, sizeof(size_t));
+ p += sizeof(size_t);
+ memcpy(history, p, sizeof(size_t)*NAVIGATION_HISTORY_SIZE);
+ src = p + sizeof(size_t)*NAVIGATION_HISTORY_SIZE;
+ srclen -= sizeof(size_t)*(3+NAVIGATION_HISTORY_SIZE);
+ }
+ printf("<%u,%u,%u>\n", historystart, historyend, historycurrent);
+ for (int i = historystart; i <= historyend; i++)
+ printf("<%u> ", history[i]);
+ printf("\n");
+}
diff --git a/noncore/apps/opie-reader/Navigation.h b/noncore/apps/opie-reader/Navigation.h
new file mode 100644
index 0000000..57fb006
--- a/dev/null
+++ b/noncore/apps/opie-reader/Navigation.h
@@ -0,0 +1,16 @@
+#include <stdlib.h>
+
+const size_t NAVIGATION_HISTORY_SIZE = 32;
+
+class CNavigation
+{
+ size_t history[NAVIGATION_HISTORY_SIZE];
+ size_t historystart, historyend, historycurrent;
+ public:
+ CNavigation() : historystart(0),historyend(0),historycurrent(0) {}
+ void saveposn(size_t posn);
+ bool forward(size_t& loc);
+ bool back(size_t& loc);
+ void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
+ void putSaveData(unsigned char*& src, unsigned short& srclen);
+};
diff --git a/noncore/apps/opie-reader/Palm2QImage.cpp b/noncore/apps/opie-reader/Palm2QImage.cpp
new file mode 100644
index 0000000..ef88cc5
--- a/dev/null
+++ b/noncore/apps/opie-reader/Palm2QImage.cpp
@@ -0,0 +1,290 @@
+/* -*- mode: c; indent-tabs-mode: nil; -*- */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h> /* for link */
+#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];
+ 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;
+ }
+
+ QImage* qimage = new QImage(width, height, 16);
+
+ /* 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) {
+
+ /* 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;
+ }
+
+ /* 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 = (inbyte[0] << 8) | inbyte[1];
+#if 0
+ qDebug ("pixel is %d,%d (%02x:%02x:%02x)",
+ j, i,
+ (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1),
+ (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1),
+ (inval >> 0) & ((1 << palm_blue_bits) - 1));
+#endif
+ QRgb colour = qRgb(
+ (inval >> (bits_per_pixel - palm_red_bits)) & ((1 << palm_red_bits) - 1),
+ (inval >> palm_blue_bits) & ((1 << palm_green_bits) - 1),
+ (inval >> 0) & ((1 << palm_blue_bits) - 1));
+ qimage->setPixel(j, i, colour);
+ inbyte += 2;
+ }
+ }
+ }
+
+ delete [] rowbuf;
+ delete [] lastrow;
+
+ return qimage;
+}
+
+QPixmap* hRule(int w, int h, unsigned char r, unsigned char g, unsigned char b)
+{
+// qDebug("hrule [%d, %d]", w, h);
+ QPixmap* qimage = new QPixmap(w, h);
+ qimage->fill(QColor(r,g,b));
+ return qimage;
+}
diff --git a/noncore/apps/opie-reader/Palm2QImage.h b/noncore/apps/opie-reader/Palm2QImage.h
new file mode 100644
index 0000000..3ac2d19
--- a/dev/null
+++ b/noncore/apps/opie-reader/Palm2QImage.h
@@ -0,0 +1,7 @@
+#include <qimage.h>
+#include <qpixmap.h>
+
+QImage* Palm2QImage
+(unsigned char *image_bytes_in, int byte_count_in);
+
+QPixmap* hRule(int w, int h, unsigned char r=0, unsigned char g=0, unsigned char b=0);
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 7cf08e5..3995ee7 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -22,6 +22,7 @@
#include <qfontdatabase.h>
#include <qpe/global.h>
#include <qpe/qcopenvelope_qws.h>
+#include "StateData.h"
#ifdef _UNICODE
const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
@@ -35,7 +36,7 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 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};
-QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
+QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
QWidget(parent, name, f),
m_delay(100),
m_scrolldy1(0),
@@ -48,7 +49,9 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
m_fm(NULL),
mouseUpOn(true),
m_twotouch(true),
- m_touchone(true)
+ m_touchone(true),
+ bDoUpdates(false),
+ m_navkeys(true)
{
m_overlap = 1;
// init();
@@ -81,21 +84,60 @@ long QTReader::real_delay()
void QTReader::mousePressEvent( QMouseEvent* _e )
{
+ buffdoc.unsuspend();
if (_e->button() == RightButton)
{
mouseUpOn = false;
- if (_e->y() > height()/2)
+ if (buffdoc.hasnavigation())
{
- goDown();
+ if (_e->y() > (2*height())/3)
+ {
+ goDown();
+ }
+ else if (_e->y() < height()/3)
+ {
+ goUp();
+ }
+ else
+ {
+ if (_e->x() < width()/3)
+ {
+ size_t target = pagelocate();
+ if (buffdoc.back(target))
+ {
+ locate(target);
+ }
+ }
+ else if (_e->x() > (2*width())/3)
+ {
+ size_t target = pagelocate();
+ if (buffdoc.forward(target))
+ {
+ locate(target);
+ }
+ }
+ else
+ {
+ buffdoc.saveposn(pagelocate());
+ locate(buffdoc.getHome());
+ }
+ }
}
else
{
- goUp();
+ if (_e->y() > height()/2)
+ {
+ goDown();
+ }
+ else
+ {
+ goUp();
+ }
}
}
}
-bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
+linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
{
int lineno = 0;
int ht = textarray[0]->lineSpacing();
@@ -112,10 +154,11 @@ bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t
{
int i;
CDrawBuffer* t = textarray[lineno];
- for (i = t->length(); t->width(i) > x; i--);
+ x = x - t->offset(width());
+ for (i = t->length(); i >= 0 && t->width(i) > x; i--);
offset = i;
}
- return textarray[lineno]->isLink(offset, tgt);
+ return textarray[lineno]->getLinkType(offset, tgt);
}
void QTReader::setTwoTouch(bool _b)
@@ -124,8 +167,15 @@ void QTReader::setTwoTouch(bool _b)
m_twotouch = m_touchone = _b;
}
+void QTReader::setContinuous(bool _b)
+{
+ buffdoc.unsuspend();
+ buffdoc.setContinuous(m_continuousDocument = _b);
+}
+
void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
+ buffdoc.unsuspend();
if (_e->button() == LeftButton)
{
if (mouseUpOn)
@@ -141,18 +191,43 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
ht += textarray[++lineno]->lineSpacing();
}
size_t startpos, startoffset, tgt;
- if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
+ switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
{
- if (buffdoc.hyperlink(tgt))
+ case eLink:
{
- fillbuffer();
- update();
+ size_t saveposn = pagelocate();
+ if (buffdoc.hyperlink(tgt))
+ {
+ buffdoc.saveposn(saveposn);
+ fillbuffer();
+ update();
+ }
+ else
+ {
+ locate(pagelocate());
+ }
+ return;
}
- else
+ case ePicture:
{
- locate(pagelocate());
+ qDebug("Picture:%x", tgt);
+ QPixmap* pm = buffdoc.getPicture(tgt);
+ if (pm != NULL)
+ {
+ emit OnShowPicture(*pm);
+ delete pm;
+ }
+ else
+ {
+ locate(pagelocate());
+ }
+ return;
}
- return;
+ case eNone:
+ break;
+ default:
+ qDebug("Unknown linktype");
+ return;
}
if (m_twotouch)
{
@@ -212,11 +287,12 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
CDrawBuffer* t = textarray[lineno];
int first = 0;
+ int tgt = _e->x() - t->offset(width());
while (1)
{
int i = first+1;
while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
- if (t->width(i) > _e->x())
+ if (t->width(i) > tgt)
{
wrd = toQString(t->data()+first, i - first);
break;
@@ -282,8 +358,77 @@ void QTReader::goUp()
}
}
+void QTReader::NavUp()
+{
+ buffdoc.unsuspend();
+ if (buffdoc.hasnavigation())
+ {
+/*
+ size_t target = pagelocate();
+ if (buffdoc.back(target))
+ {
+ locate(target);
+ }
+*/
+ locate(buffdoc.startSection());
+ }
+ else
+ {
+ goUp();
+ }
+}
+
+void QTReader::NavDown()
+{
+ buffdoc.unsuspend();
+ if (buffdoc.hasnavigation())
+ {
+/*
+ size_t target = pagelocate();
+ if (buffdoc.forward(target))
+ {
+ locate(target);
+ }
+*/
+ dopageup(buffdoc.endSection());
+ }
+ else
+ {
+ goDown();
+ }
+}
+
+void QTReader::zoomin()
+{
+ if (m_fontControl.increasesize())
+ {
+ bool sc = m_autoScroll;
+ setfont();
+ m_autoScroll = false;
+ locate(pagelocate());
+ update();
+ m_autoScroll = sc;
+ if (m_autoScroll) autoscroll();
+ }
+}
+
+void QTReader::zoomout()
+{
+ if (m_fontControl.decreasesize())
+ {
+ bool sc = m_autoScroll;
+ m_autoScroll = false;
+ setfont();
+ locate(pagelocate());
+ update();
+ m_autoScroll = sc;
+ if (m_autoScroll) autoscroll();
+ }
+}
+
void QTReader::keyPressEvent(QKeyEvent* e)
{
+ buffdoc.unsuspend();
switch (e->key())
{
case Key_Down:
@@ -357,36 +502,34 @@ void QTReader::keyPressEvent(QKeyEvent* e)
}
break;
*/
- case Key_Right:
+ case Key_Right:
{
- e->accept();
- if (m_fontControl.increasesize())
- {
- bool sc = m_autoScroll;
- setfont();
- m_autoScroll = false;
- locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
- }
+ e->accept();
+ if (m_navkeys && buffdoc.hasnavigation())
+ {
+ size_t target = pagelocate();
+ if (buffdoc.forward(target))
+ {
+ locate(target);
+ }
+ }
+ else zoomin();
}
- break;
- case Key_Left:
+ break;
+ case Key_Left:
{
- e->accept();
- if (m_fontControl.decreasesize())
- {
- bool sc = m_autoScroll;
- m_autoScroll = false;
- setfont();
- locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
- }
+ e->accept();
+ if (m_navkeys && buffdoc.hasnavigation())
+ {
+ size_t target = pagelocate();
+ if (buffdoc.back(target))
+ {
+ locate(target);
+ }
+ }
+ else zoomout();
}
- break;
+ break;
case Key_Space:
case Key_Return:
{
@@ -409,6 +552,8 @@ void QTReader::setautoscroll(bool _sc)
}
else
{
+ CDrawBuffer* reusebuffer = textarray[numlines];
+ if (reusebuffer == NULL || reusebuffer->eof()) return;
m_autoScroll = true;
autoscroll();
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
@@ -417,6 +562,7 @@ void QTReader::setautoscroll(bool _sc)
bool QTReader::getline(CDrawBuffer *buff)
{
+ buffdoc.unsuspend();
if (m_bMonoSpaced)
{
return buffdoc.getline(buff ,width(), m_charWidth);
@@ -459,17 +605,16 @@ void QTReader::doscroll()
if (textarray[numlines] == NULL)
{
- textarray[numlines] = new CDrawBuffer;
+ textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
locnarray[numlines] = locate();
int ch = getline(textarray[numlines]);
- textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
+ textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
mylastpos = locate();
if (!ch)
{
m_autoScroll = false;
((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
- emit OnRedraw();
}
emit OnRedraw();
}
@@ -492,78 +637,70 @@ void QTReader::setfont()
void QTReader::drawFonts( QPainter *p )
{
- setfont();
- if (m_lastwidth != width() || m_lastheight != height())
- {
- m_lastwidth = width();
- m_lastheight = height();
- locate(pagelocate());
- }
- else
- {
-
-/*
- int sl = screenlines();
- if (sl < numlines)
- {
-// qDebug("df:<%u,%u>",sl,numlines);
-
- size_t newpos = locnarray[sl];
- CDrawBuffer** nta = new CDrawBuffer*[sl];
- size_t* nla = new size_t[sl];
- for (int i = 0; i < sl; i++)
- {
- nta[i] = textarray[i];
- nla[i] = locnarray[i];
- }
- for (int i = sl; i < numlines; i++) delete textarray[i];
- delete [] locnarray;
- delete [] textarray;
- textarray = nta;
- locnarray = nla;
- numlines = sl;
- jumpto(mylastpos = newpos);
- }
- if (sl > numlines)
- {
-// qDebug("df:<%u,%u>",sl,numlines);
- CDrawBuffer** nta = new CDrawBuffer*[sl];
- size_t* nla = new size_t[sl];
- for (int i = 0; i < numlines; i++)
- {
- nta[i] = textarray[i];
- nla[i] = locnarray[i];
- }
- if (locate() != mylastpos) jumpto(mylastpos);
- for (int i = numlines; i < sl; i++)
- {
- nta[i] = new CDrawBuffer(&m_fontControl);
- nla[i] = locate();
- getline(nta[i]);
- }
- mylastpos = locate();
- delete [] locnarray;
- delete [] textarray;
- textarray = nta;
- locnarray = nla;
- numlines = sl;
- }
-*/
- if (numlines > 0)
- {
- int ypos = textarray[0]->ascent();
- textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
- for (int i = 1; i < numlines; i++)
- {
- ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
- textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
-
- }
+ if (bDoUpdates)
+ {
+ qDebug("How refreshing...");
+ if (buffdoc.empty()) return;
+ setfont();
+ if (m_lastwidth != width())
+ {
+ qDebug("Not Optimised %d", m_lastwidth);
+ m_lastwidth = width();
+ m_lastheight = height();
+ locate(pagelocate());
+ qDebug("Not Optimised %d", m_lastwidth);
+ }
+ else
+ {
+ if (m_lastheight > height())
+ {
+ qDebug("Optimised < %d", numlines);
+ int ypos = 0;
+ for (int i = 0; i < numlines; i++)
+ {
+ if ((ypos += textarray[i]->lineSpacing()) > height())
+ {
+ numlines = i;
+ jumpto(locnarray[i+1]);
+ break;
+ }
+ }
+ qDebug("Optimised < %d", numlines);
+ m_lastheight = height();
+ }
+ else if (m_lastheight < height())
+ {
+ qDebug("Optimised > %d", numlines);
+ int ypos = 0;
+ for (int i = 0; i <= numlines; i++)
+ {
+ ypos += textarray[i]->lineSpacing();
+ }
+ fillbuffer(numlines+1, ypos);
+ qDebug("Optimised > %d", numlines);
+ m_lastheight = height();
+ }
+ if (numlines > 0)
+ {
+ int ypos = textarray[0]->ascent();
+ textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
+ for (int i = 1; i < numlines; i++)
+ {
+// ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
+ ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
+ (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
+ textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
+ }
// mylastpos = locate();
- }
- }
- m_scrolldy1 = m_scrolldy2 = 0;
- emit OnRedraw();
+ }
+ }
+ m_scrolldy1 = m_scrolldy2 = 0;
+ emit OnRedraw();
+ }
+ else
+ {
+ qDebug("Not so refreshing...");
+ }
}
QString QTReader::firstword()
@@ -607,6 +744,7 @@ void QTReader::init()
{
// setCaption( "Qt Draw Demo Application" );
+ buffdoc.unsuspend();
setBackgroundColor( white );
// QPainter p(this);
// p.setBackgroundMode( Qt::OpaqueMode );
@@ -618,14 +756,14 @@ void QTReader::init()
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
// QMessageBox::information(this, "init", m_lastfile, 1);
- m_lastwidth = width();
- m_lastheight = height();
setfont();
+/*
if (!m_lastfile.isEmpty())
{
m_string = DocLnk(m_lastfile).name();
load_file(m_lastfile);
}
+*/
}
//
@@ -701,6 +839,7 @@ int main( int argc, tchar **argv )
bool QTReader::locate(unsigned long n) {
//printf("Locate\n");
+ buffdoc.unsuspend();
buffdoc.locate(n);
// qDebug("&buffdoc.located");
fillbuffer();
@@ -719,6 +858,7 @@ unsigned int QTReader::screenlines()
bool QTReader::fillbuffer(int reuse, int ht)
{
+ buffdoc.unsuspend();
if (buffdoc.empty()) return false;
m_scrolldy1 = m_scrolldy2 = 0;
int ch;
@@ -726,7 +866,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
unsigned int oldpagepos = locnarray[reuse];
int ypos = ht;
numlines = reuse;
- while (ypos < height())
+ while (ypos < height() || numlines < 2)
{
if (textarray[numlines] == NULL)
{
@@ -738,7 +878,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
numlines++;
if (!ch)
{
- if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/)
+ if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
{
locate(oldpagepos);
return false;
@@ -761,6 +901,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
void QTReader::dopagedn()
{
+ buffdoc.unsuspend();
int skip = 0, ypos = 0;
if (locate() != mylastpos)
{
@@ -768,6 +909,7 @@ void QTReader::dopagedn()
jumpto(mylastpos);
}
CDrawBuffer* reusebuffer = textarray[numlines];
+ if (reusebuffer != NULL && reusebuffer->eof()) return;
if (reusebuffer != NULL)
{
for (int i = 0; i <= m_overlap; i++)
@@ -777,6 +919,7 @@ void QTReader::dopagedn()
size_t reuselocn = locnarray[offset];
textarray[offset] = textarray[i];
textarray[i] = reusebuffer;
+// reusebuffer->empty();
locnarray[offset] = locnarray[i];
locnarray[i] = reuselocn;
ypos += textarray[i]->lineSpacing();
@@ -791,50 +934,73 @@ void QTReader::dopagedn()
void QTReader::dopageup()
{
+ buffdoc.unsuspend();
+ dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
+}
+
+void QTReader::dopageup(unsigned int target)
+{
+ buffdoc.unsuspend();
CBufferFace<CDrawBuffer*> buff;
CBufferFace<size_t> loc;
- unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
- size_t delta;
- if (target < 2048)
- {
- delta = target;
- jumpto(0);
- }
- else
- {
- delta = 2048;
+ size_t delta, guess = 2048;
+ bool ch = true;
+ int nbfl, ypos = 0;
- jumpto(target - delta);
-
- buff[0] = new CDrawBuffer(&m_fontControl);
-
- do
+ while (1)
+ {
+ ch = true;
+ nbfl = 0;
+ if (target < guess)
+ {
+ delta = 0; // 0 is a flag to say don't guess any more
+ jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
+ }
+ else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
+ {
+ delta = 0; // 0 is a flag to say don't guess any more
+ jumpto(buffdoc.startSection());
+ }
+ else
{
+ delta = guess;
- if (!getline(buff[0])) break;
+ jumpto(target - delta);
- if (locate() > target) continue;
+ buff[0] = new CDrawBuffer(&m_fontControl);
+
+ do
+ {
+
+ if (!getline(buff[0])) break;
+
+ if (locate() > target) break;
+ }
+ while (!buffdoc.iseol());
}
- while (!buffdoc.iseol());
- }
- int nbfl = 0;
-
- bool ch = true;
- int ypos = 0;
- while (locate() < target)
- {
- if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
- loc[nbfl] = locate();
- ch = getline(buff[nbfl]);
- ypos += buff[nbfl]->lineSpacing();
- nbfl++;
- if (!ch) break;
- }
- if (ypos < height())
- {
- locate(0);
- return;
+
+ ypos = 0;
+ while (locate() < target)
+ {
+ if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
+ loc[nbfl] = locate();
+ ch = getline(buff[nbfl]);
+ ypos += buff[nbfl]->lineSpacing();
+ nbfl++;
+ if (!ch) break;
+ }
+ if (ypos < height() && (delta != 0))
+ {
+ for (int i = 0; i < nbfl; i++)
+ {
+ delete buff[i];
+ buff[i] = NULL;
+ }
+ guess <<= 1;
+ continue;
+ }
+ break;
}
if (ch)
{
@@ -845,26 +1011,36 @@ void QTReader::dopageup()
}
ypos = 0;
numlines = 0;
- while (ypos < height() && numlines <= nbfl-2)
+ while (ypos < height() && numlines <= nbfl-1)
{
- ypos += buff[nbfl - numlines - 2]->lineSpacing();
+ ypos += buff[nbfl - numlines - 1]->lineSpacing();
numlines++;
}
--numlines;
- int offset = nbfl;
- offset -= numlines+1;
+ int offset = nbfl-1;
+ offset -= numlines;
+ ypos = 0;
for (int i = 0; i <= numlines; i++)
{
delete textarray[i];
textarray[i] = buff[offset+i];
locnarray[i] = loc[offset + i];
+ ypos += textarray[i]->lineSpacing();
}
for (int i = 0; i < nbfl - numlines - 1; i++)
{
delete buff[i];
}
-// --numlines;
+ while (ypos < height())
+ {
+ numlines++;
+ locnarray[numlines] = locate();
+ if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
+ if (!getline(textarray[numlines])) break;
+ ypos += textarray[numlines]->lineSpacing();
+ }
+
mylastpos = locate();
update();
@@ -883,9 +1059,12 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
}
m_lastfile = newfile;
// QMessageBox::information(0, "Opening...", newfile);
+ m_lastwidth = width();
+ m_lastheight = height();
if (buffdoc.openfile(this,newfile) == 0)
{
bRC = true;
+ buffdoc.setContinuous(m_continuousDocument);
// qDebug("buffdoc.openfile done");
locate(lcn);
// qDebug("buffdoc.locate done");
@@ -1012,6 +1191,7 @@ void QTReader::lineUp()
*/
void QTReader::lineUp()
{
+ buffdoc.unsuspend();
CDrawBuffer* buff = textarray[numlines];
unsigned int loc;
unsigned int end = locnarray[numlines];
@@ -1019,6 +1199,7 @@ void QTReader::lineUp()
if (locate() != mylastpos) jumpto(mylastpos);
unsigned int target = locnarray[0];
if (target == 0) return;
+ if (!m_continuousDocument && (target == buffdoc.startSection())) return;
if (buffdoc.hasrandomaccess())
{
unsigned int delta = locate()-pagelocate();
@@ -1034,6 +1215,14 @@ void QTReader::lineUp()
getline(buff);
break;
}
+ else if (!m_continuousDocument && (target - delta < buffdoc.startSection()))
+ {
+ delta = target-buffdoc.startSection();
+ jumpto(buffdoc.startSection());
+ loc = locate();
+ getline(buff);
+ break;
+ }
jumpto(target-delta);
do
{
@@ -1107,3 +1296,32 @@ MarkupType QTReader::PreferredMarkup()
}
return m;
}
+
+void QTReader::setstate(const statedata& sd)
+{
+ bstripcr = sd.bstripcr;
+ btextfmt = sd.btextfmt;
+ bautofmt = sd.bautofmt;
+ bstriphtml = sd.bstriphtml;
+ bpeanut = sd.bpeanut;
+ bdehyphen = sd.bdehyphen;
+ bonespace = sd.bonespace;
+ bunindent = sd.bunindent;
+ brepara = sd.brepara;
+ bdblspce = sd.bdblspce;
+ m_bpagemode = sd.m_bpagemode;
+ m_navkeys = sd.m_navkeys;
+ m_bMonoSpaced = sd.m_bMonoSpaced;
+ bremap = sd.bremap;
+ bmakebold = sd.bmakebold;
+ m_continuousDocument = sd.Continuous;
+#ifdef REPALM
+ brepalm = sd.brepalm;
+#endif
+ bindenter = sd.bindenter;
+ m_encd = sd.m_charpc;
+ m_fontname = sd.m_fontname;
+ setContinuous(sd.Continuous);
+ ChangeFont(sd.m_textsize);
+ refresh();
+}
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
index 78230b4..3d5f57d 100644
--- a/noncore/apps/opie-reader/QTReader.h
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -13,12 +13,15 @@ class CDrawBuffer;
//class CBuffer;
class QPainter;
class QTimer;
+class QPixmap;
+class statedata;
class QTReader : public QWidget
{
Q_OBJECT
friend class QTReaderApp;
+ void suspend() { buffdoc.suspend(); }
void drawText(QPainter& p, int x, int y, tchar* text);
int m_delay;
unsigned int m_overlap;
@@ -37,7 +40,18 @@ 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();
+ 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; }
@@ -108,6 +122,18 @@ public:
bstripcr = _b;
setfilter(getfilter());
}
+ void setonespace(bool _b)
+ {
+ bonespace = _b;
+ setfilter(getfilter());
+ }
+#ifdef REPALM
+ void setrepalm(bool _b)
+ {
+ brepalm = _b;
+ setfilter(getfilter());
+ }
+#endif
void setstriphtml(bool _b)
{
bstriphtml = _b;
@@ -190,8 +216,12 @@ public:
if (bdehyphen) filt->addfilter(new dehyphen);
if (bunindent) filt->addfilter(new unindent);
if (brepara) filt->addfilter(new repara);
+ if (bonespace) filt->addfilter(new OnePara);
if (bindenter) filt->addfilter(new indenter(bindenter));
if (bdblspce) filt->addfilter(new dblspce);
+#ifdef REPALM
+ if (brepalm) filt->addfilter(new repalm);
+#endif
if (bremap) filt->addfilter(new remap);
if (bmakebold) filt->addfilter(new embolden);
return filt;
@@ -216,9 +246,10 @@ private slots:
//myoutput stuff
private:
bool mouseUpOn;
- bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
+ linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
bool m_twotouch, m_touchone;
size_t m_startpos, m_startoffset;
+ void dopageup(unsigned int);
void dopageup();
void lineDown();
void lineUp();
@@ -229,24 +260,31 @@ private slots:
CBufferFace<CDrawBuffer*> textarray;
CBufferFace<size_t> locnarray;
unsigned int numlines;
- bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt;
- bool m_bpagemode, m_bMonoSpaced;
+ bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace;
+#ifdef REPALM
+ bool brepalm;
+#endif
+ bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
unsigned char bindenter;
QString m_lastfile;
size_t m_lastposn;
public:
+ bool bDoUpdates;
+ bool m_navkeys;
+ void NavUp();
+ void NavDown();
int getch() { return buffdoc.getch(); }
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(); }
+ void jumpto(unsigned long n) { buffdoc.unsuspend(); buffdoc.locate(n); }
+ unsigned long locate() { buffdoc.unsuspend(); return buffdoc.locate(); }
+ unsigned long explocate() { buffdoc.unsuspend(); return buffdoc.explocate(); }
unsigned long pagelocate() { return locnarray[0]; }
unsigned long mylastpos;
- void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); }
+ void setfilter(CFilterChain *f) { buffdoc.unsuspend(); buffdoc.setfilter(f); locate(pagelocate()); }
void restore() { jumpto(mylastpos); }
void goUp();
void refresh() { locate(pagelocate()); }
@@ -256,17 +294,19 @@ private slots:
void textsize(int ts) { m_textsize = ts; }
bool fillbuffer(int ru = 0, int ht = 0);
unsigned int screenlines();
- void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); }
+ void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.unsuspend(); buffdoc.sizes(fs,ts); }
static const char *fonts[];
// unsigned int *fontsizes;
int m_ascent, m_descent, m_linespacing;
QFontMetrics* m_fm;
QString firstword();
+ void setstate(const statedata& sd);
signals:
void OnRedraw();
void OnWordSelected(const QString&, size_t, const QString&);
void OnActionPressed();
+ void OnShowPicture(QPixmap&);
};
#endif
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp
index 8726df7..2044b1d 100644
--- a/noncore/apps/opie-reader/QTReaderApp.cpp
+++ b/noncore/apps/opie-reader/QTReaderApp.cpp
@@ -1,5 +1,5 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000 Trolltech AS. Allrights reserved.
**
** This file is part of Qt Palmtop Environment.
**
@@ -21,7 +21,10 @@
#include <qclipboard.h>
#include <qwidgetstack.h>
#include <qpe/qpemenubar.h>
-#include <qpe/qpetoolbar.h>
+//#include <qpe/qpetoolbar.h>
+#include <qmenubar.h>
+#include <qtoolbar.h>
+#include <qpe/menubutton.h>
#include <qpe/fontdatabase.h>
#include <qcombobox.h>
#include <qpopupmenu.h>
@@ -42,6 +45,7 @@
#include <qpe/qcopenvelope_qws.h>
#include "QTReader.h"
+#include "GraphicWin.h"
#include "Bkmks.h"
#include "cbkmkselector.h"
#include "infowin.h"
@@ -55,6 +59,16 @@
#include "QTReaderApp.h"
#include "fileBrowser.h"
#include "CDrawBuffer.h"
+#include "Filedata.h"
+#include "opie.h"
+#include "name.h"
+#include "StateData.h"
+
+#ifdef OPIE
+#define PICDIR "opie-reader/"
+#else
+#define PICDIR
+#endif
unsigned long QTReaderApp::m_uid = 0;
@@ -68,22 +82,23 @@ void QTReaderApp::setScrollState(bool _b) { m_scrollButton->setOn(_b); }
void QTReaderApp::listBkmkFiles()
{
bkmkselector->clear();
+ bkmkselector->setText("Cancel");
int cnt = 0;
DIR *d;
- d = opendir((const char *)Global::applicationFileName("uqtreader",""));
+ d = opendir((const char *)Global::applicationFileName(APPDIR,""));
while(1)
{
- struct dirent* de;
- struct stat buf;
- de = readdir(d);
- if (de == NULL) break;
+ struct dirent* de;
+ struct stat buf;
+ de = readdir(d);
+ if (de == NULL) break;
- if (lstat((const char *)Global::applicationFileName("uqtreader",de->d_name),&buf) == 0 && S_ISREG(buf.st_mode))
- {
- bkmkselector->insertItem(de->d_name);
- cnt++;
- }
+ 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);
@@ -93,13 +108,21 @@ void QTReaderApp::listBkmkFiles()
//tjw menu->hide();
editBar->hide();
if (m_fontVisible) m_fontBar->hide();
- if (regVisible) regBar->hide();
- if (searchVisible) searchBar->hide();
- m_nRegAction = cRmBkmkFile;
+ if (regVisible)
+ {
+ Global::hideInputMethod();
+ regBar->hide();
+ }
+ if (searchVisible)
+ {
+ Global::hideInputMethod();
+ searchBar->hide();
+ }
+ m_nRegAction = cRmBkmkFile;
editorStack->raiseWidget( bkmkselector );
}
else
- QMessageBox::information(this, "OpieReader", "No bookmark files");
+ QMessageBox::information(this, PROGNAME, "No bookmark files");
}
QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
@@ -109,23 +132,26 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml"));
pBkmklist = NULL;
- doc = 0;
+ pOpenlist = NULL;
+// doc = 0;
- m_fBkmksChanged = false;
+ m_fBkmksChanged = false;
QString lang = getenv( "LANG" );
- m_autogenstr = "^ *[A-Z].*[a-z] *$";
+ m_autogenstr = "^ *[A-Z].*[a-z] *$";
setToolBarsMovable( FALSE );
- setIcon( Resource::loadPixmap( "opie-reader/uqtreader" ) );
+ setIcon( Resource::loadPixmap( "uqtreader" ) );
- QPEToolBar *bar = new QPEToolBar( this );
+// QPEToolBar *bar = new QPEToolBar( this );
+ QToolBar *bar = new QToolBar( this );
bar->setHorizontalStretchable( TRUE );
addToolBar(bar, "tool",QMainWindow::Top, true);
//tjw menu = bar;
QPEMenuBar *mb = new QPEMenuBar( bar );
+// QMenuBar *mb = new QMenuBar( bar );
QPopupMenu *file = new QPopupMenu( this );
QPopupMenu *format = new QPopupMenu( this );
// QPopupMenu *edit = new QPopupMenu( this );
@@ -159,6 +185,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
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&) ) );
@@ -175,12 +205,17 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
// don't need the close visible, it is redundant...
importSelector->setCloseVisible( FALSE );
*/
+ qDebug("Reading file list");
+ readfilelist();
reader = new QTReader( editorStack );
+ reader->bDoUpdates = false;
+
((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
- Config config( "uqtreader" );
+ qDebug("Reading config");
+ Config config( APPDIR );
config.setGroup( "View" );
reader->bstripcr = config.readBoolEntry( "StripCr", true );
@@ -189,6 +224,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
reader->bpeanut = config.readBoolEntry( "Peanut", false );
reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
+ reader->bonespace = config.readBoolEntry( "OneSpace", false );
reader->bunindent = config.readBoolEntry( "Unindent", false );
reader->brepara = config.readBoolEntry( "Repara", false );
reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
@@ -198,13 +234,18 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
reader->m_lastfile = config.readEntry( "LastFile", QString::null );
reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
reader->m_bpagemode = config.readBoolEntry( "PageMode", true );
+ reader->m_navkeys = config.readBoolEntry( "CursorNavigation", false );
reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false);
reader->m_fontname = config.readEntry( "Fontname", "helvetica" );
reader->m_encd = config.readNumEntry( "Encoding", 0 );
reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
reader->m_overlap = config.readNumEntry( "Overlap", 0 );
+#ifdef REPALM
+ reader->brepalm = config.readBoolEntry( "Repalm", true );
+#endif
reader->bremap = config.readBoolEntry( "Remap", true );
reader->bmakebold = config.readBoolEntry( "MakeBold", false );
+ reader->setContinuous(config.readBoolEntry( "Continuous", true ));
m_targetapp = config.readEntry( "TargetApp", QString::null );
m_targetmsg = config.readEntry( "TargetMsg", QString::null );
m_twoTouch = config.readBoolEntry( "TwoTouch", false);
@@ -215,6 +256,8 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
setTwoTouch(m_twoTouch);
+ connect( reader, SIGNAL( OnShowPicture(QPixmap&) ), this, SLOT( showgraphic(QPixmap&) ) );
+
connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) );
connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) );
@@ -225,6 +268,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
a->addTo( bar );
a->addTo( file );
+ a = new QAction( tr( "Close" ), Resource::loadPixmap( "fileclose" ), QString::null, 0, this, 0 );
+ connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) );
+// a->addTo( bar );
+ a->addTo( file );
+
/*
a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) );
@@ -250,18 +298,40 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true );
+ m_buttonAction[3] = new QAction( tr( "Fullscreen" ), QString::null, 0, ag, NULL, true );
+
ag->addTo(spacemenu);
connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) );
+ file->insertSeparator();
+
+ ag = new QActionGroup(this);
+ ag->setExclusive(false);
+ QPopupMenu *encoding = new QPopupMenu(this);
+ file->insertItem( tr( "Navigation" ), encoding );
+
+ a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( PICDIR "panel-arrow-down" ), QString::null, 0, ag, 0, true );
- a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( "opie-reader/panel-arrow-down" ), QString::null, 0, this, 0, true );
-// connect( a, SIGNAL( activated() ), this, SLOT( autoScroll() ) );
a->setOn(false);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
- file->insertSeparator();
a->addTo( bar );
- a->addTo( file );
+
+ a = new QAction( tr( "Jump" ), QString::null, 0, ag, NULL);
+ connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
+
+ a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
+ a->setOn(reader->m_bpagemode);
+
+ a = new QAction( tr( "Set Overlap" ), QString::null, 0, ag, NULL);
+ connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
+
+ a = new QAction( tr( "Use Cursor" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( navkeys(bool) ) );
+ a->setOn(reader->m_navkeys);
+
+ ag->addTo(encoding);
/*
a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true );
@@ -272,18 +342,6 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
// connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
a->addTo( file );
*/
- a = new QAction( tr( "Jump" ), QString::null, 0, this, NULL);
- connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
- a->addTo( file );
-
- a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, this, NULL, true );
- connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
- a->setOn(reader->m_bpagemode);
- a->addTo( file );
-
- a = new QAction( tr( "Set Overlap" ), QString::null, 0, this, NULL);
- connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
- a->addTo( file );
file->insertSeparator();
@@ -298,7 +356,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
ag = new QActionGroup(this);
ag->setExclusive(false);
- QPopupMenu *encoding = new QPopupMenu(this);
+ encoding = new QPopupMenu(this);
file->insertItem( tr( "Target" ), encoding );
a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true );
@@ -345,6 +403,17 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
a->addTo( file );
+ m_fullscreen = false;
+ a = m_actFullscreen = new QAction( tr( "Fullscreen" ), QString::null, 0, this, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) );
+ a->setOn(m_fullscreen);
+ a->addTo( file );
+
+ a = new QAction( tr( "Continuous" ), QString::null, 0, ag, NULL, true );
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( setcontinuous(bool) ) );
+ a->setOn(reader->m_continuousDocument);
+ a->addTo( file );
+
a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
a->addTo( bar );
@@ -395,6 +464,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) );
// a->addTo( format );
+ a = new QAction( tr( "Single Space" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->bonespace);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( onespace(bool) ) );
+
a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) );
a->setOn(reader->bunindent);
@@ -416,7 +489,11 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) );
-
+#ifdef REPALM
+ a = new QAction( tr( "Repalm" ), QString::null, 0, ag, NULL, true );
+ a->setOn(reader->brepalm);
+ connect( a, SIGNAL( toggled(bool) ), this, SLOT( repalm(bool) ) );
+#endif
a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) );
a->setOn(reader->bremap);
@@ -429,17 +506,20 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
// a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true );
// a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
- a = new QAction( tr( "Zoom" ), QString::null, 0, this);
- connect( a, SIGNAL( activated() ), this, SLOT( TBDzoom() ) );
format->insertSeparator();
+ a = new QAction( tr( "Zoom In" ), QString::null, 0, this);
+ connect( a, SIGNAL( activated() ), this, SLOT( zoomin() ) );
+ a->addTo( format );
+ a = new QAction( tr( "Zoom Out" ), QString::null, 0, this);
+ connect( a, SIGNAL( activated() ), this, SLOT( zoomout() ) );
a->addTo( format );
// a->addTo( editBar );
+ format->insertSeparator();
a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) );
a->setOn(reader->m_bMonoSpaced);
- format->insertSeparator();
a->addTo( format );
a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL);
@@ -537,10 +617,10 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
#ifdef __ISEARCH
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
- this, SLOT( search( const QString& ) ) );
+ this, SLOT( search( const QString& ) ) );
#else
connect( searchEdit, SIGNAL( returnPressed( ) ),
- this, SLOT( search( ) ) );
+ this, SLOT( search( ) ) );
#endif
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
@@ -563,7 +643,7 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
regBar->setStretchableWidget( regEdit );
connect( regEdit, SIGNAL( returnPressed( ) ),
- this, SLOT( do_regaction() ) );
+ this, SLOT( do_regaction() ) );
a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
@@ -579,45 +659,94 @@ QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
m_fontBar->setHorizontalStretchable( TRUE );
+ qDebug("Font selector");
m_fontSelector = new QComboBox(false, m_fontBar);
m_fontBar->setStretchableWidget( m_fontSelector );
{
- FontDatabase f;
- QStringList flist = f.families();
- m_fontSelector->insertStringList(flist);
-
- bool realfont = false;
- for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
- {
- if (reader->m_fontname == *nm)
- {
- realfont = true;
- break;
- }
- }
- if (!realfont) reader->m_fontname = flist[0];
+ FontDatabase f;
+ QStringList flist = f.families();
+ m_fontSelector->insertStringList(flist);
+
+ bool realfont = false;
+ for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
+ {
+ if (reader->m_fontname == *nm)
+ {
+ realfont = true;
+ }
+ if (*nm == "courier") reader->m_fontControl.hasCourier(true);
+ }
+ if (!realfont) reader->m_fontname = flist[0];
} // delete the FontDatabase!!!
connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
- this, SLOT( do_setfont(const QString&) ) );
+ this, SLOT( do_setfont(const QString&) ) );
m_fontBar->hide();
m_fontVisible = false;
connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
- this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
-
+ this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
+ qDebug("Initing");
reader->init();
- if (!reader->m_lastfile.isEmpty())
- {
- openFile( reader->m_lastfile );
- doc = new DocLnk(reader->m_lastfile);
- }
+ qDebug("Inited");
m_EncodingAction[reader->m_encd]->setOn(true);
m_buttonAction[m_spaceTarget]->setOn(true);
+ qDebug("fonting");
do_setfont(reader->m_fontname);
-}
+ if (!reader->m_lastfile.isEmpty())
+ {
+ qDebug("doclnk");
+// doc = new DocLnk(reader->m_lastfile);
+ qDebug("doclnk done");
+ if (pOpenlist != NULL)
+ {
+
+/*
+ int ind = 0;
+ Bkmk* p = (*pOpenlist)[ind];
+ while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
+ {
+ p = (*pOpenlist)[++ind];
+ }
+*/
+ Bkmk* p = NULL;
+ for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
+ {
+ p = iter.pContent();
+ if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile)
+ {
+ break;
+ }
+ qDebug("Item:%s", (const char*)toQString(CFiledata(p->anno()).name()));
+ p = NULL;
+ }
+ if (p != NULL)
+ {
+ qDebug("openfrombkmk");
+ openfrombkmk(p);
+ }
+ else
+ {
+ qDebug("openfile");
+ openFile( reader->m_lastfile );
+ }
+ }
+ else
+ {
+ qDebug("Openfile 2");
+ if (!reader->m_lastfile.isNull())
+ openFile( reader->m_lastfile );
+ }
+ }
+ qApp->processEvents();
+ reader->bDoUpdates = true;
+ reader->update();
+ qDebug("finished update");
+}
+
+void QTReaderApp::suspend() { reader->suspend(); }
void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
{
@@ -628,242 +757,256 @@ void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
QDataStream stream( _data, IO_ReadOnly );
if ( msg == "info(QString)" )
{
- QString info;
- stream >> info;
- QMessageBox::information(this, "OpieReader", info);
+ QString info;
+ stream >> info;
+ QMessageBox::information(this, PROGNAME, info);
}
else if ( msg == "warn(QString)" )
{
- QString info;
- stream >> info;
- QMessageBox::warning(this, "OpieReader", info);
+ QString info;
+ stream >> info;
+ QMessageBox::warning(this, PROGNAME, info);
}
else if ( msg == "exit()" )
{
- m_dontSave = true;
- close();
+ m_dontSave = true;
+ close();
}
else if ( msg == "pageDown()" )
{
- reader->dopagedn();
+ reader->dopagedn();
}
else if ( msg == "pageUp()" )
{
- reader->dopageup();
+ reader->dopageup();
}
else if ( msg == "lineDown()" )
{
- reader->lineDown();
+ reader->lineDown();
}
else if ( msg == "lineUp()" )
{
- reader->lineUp();
+ reader->lineUp();
}
else if ( msg == "showText()" )
{
- showEditTools();
+ showEditTools();
}
else if ( msg == "File/Open(QString)" )
{
- QString info;
- stream >> info;
- openFile( info );
+ QString info;
+ stream >> info;
+ openFile( info );
}
else if ( msg == "File/Info()" )
{
- showinfo();
+ showinfo();
}
else if ( msg == "File/Start Block()" )
{
- editMark();
+ editMark();
}
else if ( msg == "File/Copy Block()" )
{
- editCopy();
+ editCopy();
}
else if ( msg == "File/Scroll(int)" )
{
- int info;
- stream >> info;
- autoScroll(info);
+ int info;
+ stream >> info;
+ autoScroll(info);
}
else if ( msg == "File/Jump(int)" )
{
- int info;
- stream >> info;
- reader->locate(info);
+ int info;
+ stream >> info;
+ reader->locate(info);
}
else if ( msg == "File/Page/Line Scroll(int)" )
{
- int info;
- stream >> info;
- pagemode(info);
+ int info;
+ stream >> info;
+ pagemode(info);
}
else if ( msg == "File/Set Overlap(int)" )
{
- int info;
- stream >> info;
- reader->m_overlap = info;
+ int info;
+ stream >> info;
+ reader->m_overlap = info;
}
else if ( msg == "File/Set Dictionary(QString)" )
{
- QString info;
- stream >> info;
- do_settarget(info);
+ QString info;
+ stream >> info;
+ do_settarget(info);
}
else if ( msg == "File/Two/One Touch(int)" )
{
- int info;
- stream >> info;
- setTwoTouch(info);
+ int info;
+ stream >> info;
+ setTwoTouch(info);
}
else if ( msg == "Target/Annotation(int)" )
{
- int info;
- stream >> info;
- OnAnnotation(info);
+ int info;
+ stream >> info;
+ OnAnnotation(info);
}
else if ( msg == "Target/Dictionary(int)" )
{
- int info;
- stream >> info;
- OnDictionary(info);
+ int info;
+ stream >> info;
+ OnDictionary(info);
}
else if ( msg == "Target/Clipboard(int)" )
{
- int info;
- stream >> info;
- OnClipboard(info);
+ int info;
+ stream >> info;
+ OnClipboard(info);
}
else if ( msg == "File/Find(QString)" )
{
- QString info;
- stream >> info;
- QRegExp arg(info);
- size_t pos = reader->pagelocate();
- size_t start = pos;
- CDrawBuffer test(&(reader->m_fontControl));
- reader->buffdoc.getline(&test,reader->width());
- while (arg.match(toQString(test.data())) == -1)
- {
- pos = reader->locate();
- if (!reader->buffdoc.getline(&test,reader->width()))
- {
- QMessageBox::information(this, "OpieReader", QString("Can't find\n")+info);
- pos = start;
- break;
- }
- }
- reader->locate(pos);
+ QString info;
+ stream >> info;
+ QRegExp arg(info);
+ size_t pos = reader->pagelocate();
+ size_t start = pos;
+ CDrawBuffer test(&(reader->m_fontControl));
+ reader->buffdoc.getline(&test,reader->width());
+ while (arg.match(toQString(test.data())) == -1)
+ {
+ pos = reader->locate();
+ if (!reader->buffdoc.getline(&test,reader->width()))
+ {
+ QMessageBox::information(this, PROGNAME, QString("Can't find\n")+info);
+ pos = start;
+ break;
+ }
+ }
+ reader->locate(pos);
}
else if ( msg == "Layout/Strip CR(int)" )
{
- int info;
- stream >> info;
- stripcr(info);
+ int info;
+ stream >> info;
+ stripcr(info);
+ }
+ else if ( msg == "Layout/Single Space" )
+ {
+ int info;
+ stream >> info;
+ onespace(info);
+ }
+#ifdef REPALM
+ else if ( msg == "Layout/Repalm(int)" )
+ {
+ int info;
+ stream >> info;
+ repalm(info);
}
+#endif
else if ( msg == "Markup/Auto(int)" )
{
- int info;
- stream >> info;
- autofmt(info);
+ int info;
+ stream >> info;
+ autofmt(info);
}
else if ( msg == "Markup/Text(int)" )
{
- int info;
- stream >> info;
- textfmt(info);
+ int info;
+ stream >> info;
+ textfmt(info);
}
else if ( msg == "Markup/HTML(int)" )
{
- int info;
- stream >> info;
- striphtml(info);
+ int info;
+ stream >> info;
+ striphtml(info);
}
else if ( msg == "Markup/Peanut(int)" )
{
- int info;
- stream >> info;
- peanut(info);
+ int info;
+ stream >> info;
+ peanut(info);
}
else if ( msg == "Layout/Dehyphen(int)" )
{
- int info;
- stream >> info;
- dehyphen(info);
+ int info;
+ stream >> info;
+ dehyphen(info);
}
else if ( msg == "Layout/Unindent(int)" )
{
- int info;
- stream >> info;
- unindent(info);
+ int info;
+ stream >> info;
+ unindent(info);
}
else if ( msg == "Layout/Re-paragraph(int)" )
{
- int info;
- stream >> info;
- repara(info);
+ int info;
+ stream >> info;
+ repara(info);
}
else if ( msg == "Layout/Double Space(int)" )
{
- int info;
- stream >> info;
- dblspce(info);
+ int info;
+ stream >> info;
+ dblspce(info);
}
else if ( msg == "Layout/Indent(int)" )
{
- int info;
- stream >> info;
- reader->bindenter = info;
- reader->setfilter(reader->getfilter());
+ int info;
+ stream >> info;
+ reader->bindenter = info;
+ reader->setfilter(reader->getfilter());
}
else if ( msg == "Layout/Remap(int)" )
{
- int info;
- stream >> info;
- remap(info);
+ int info;
+ stream >> info;
+ remap(info);
}
else if ( msg == "Layout/Embolden(int)" )
{
- int info;
- stream >> info;
- embolden(info);
+ int info;
+ stream >> info;
+ embolden(info);
}
else if ( msg == "Format/Ideogram/Word(int)" )
{
- int info;
- stream >> info;
- monospace(info);
+ int info;
+ stream >> info;
+ monospace(info);
}
else if ( msg == "Format/Set width(int)" )
{
- int info;
- stream >> info;
- reader->m_charpc = info;
- reader->setfont();
- reader->refresh();
+ int info;
+ stream >> info;
+ reader->m_charpc = info;
+ reader->setfont();
+ reader->refresh();
}
else if ( msg == "Format/Encoding(QString)" )
{
- QString info;
- stream >> info;
- reader->setencoding(EncNameToInt(info));
+ QString info;
+ stream >> info;
+ reader->setencoding(EncNameToInt(info));
}
else if ( msg == "Format/Set Font(QString,int)" )
{
- QString fontname;
- int size;
- stream >> fontname;
- stream >> size;
- setfontHelper(fontname, size);
+ QString fontname;
+ int size;
+ stream >> fontname;
+ stream >> size;
+ setfontHelper(fontname, size);
}
else if ( msg == "Marks/Autogen(QString)" )
{
- QString info;
- stream >> info;
- do_autogen(info);
+ QString info;
+ stream >> info;
+ do_autogen(info);
}
}
@@ -871,16 +1014,32 @@ ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
{
for (int i = 0; i < MAX_ACTIONS; i++)
{
- if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
+ if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
}
return cesAutoScroll;
}
+void QTReaderApp::setfullscreen(bool sfs)
+{
+ reader->bDoUpdates = false;
+ m_fullscreen = sfs;
+ showEditTools();
+ qApp->processEvents();
+ reader->bDoUpdates = true;
+ reader->update();
+}
+
+void QTReaderApp::setcontinuous(bool sfs)
+{
+ reader->setContinuous(sfs);
+ reader->refresh();
+}
+
int QTReaderApp::EncNameToInt(const QString& _enc)
{
for (int i = 0; i < MAX_ENCODING; i++)
{
- if (m_EncodingAction[i]->text() == _enc) return i;
+ if (m_EncodingAction[i]->text() == _enc) return i;
}
return 0;
/*
@@ -910,23 +1069,96 @@ QTReaderApp::~QTReaderApp()
void QTReaderApp::autoScroll(bool _b)
{
reader->setautoscroll(_b);
+ setScrollState(reader->m_autoScroll);
}
-void QTReaderApp::TBD()
+void QTReaderApp::zoomin()
{
- QMessageBox::information(this, "OpieReader", "Not yet implemented", 1);
+ reader->zoomin();
}
-void QTReaderApp::TBDzoom()
+void QTReaderApp::zoomout()
{
- QMessageBox::information(this, "OpieReader", "Zooming is done interactively\nTry left/right cursor keys", 1);
+ reader->zoomout();
}
void QTReaderApp::clearBkmkList()
{
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
+}
+
+void QTReaderApp::fileClose()
+{
+ if (pOpenlist != NULL)
+ {
+ int ind = 0;
+ Bkmk* p = (*pOpenlist)[ind];
+ while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
+ {
+ p = (*pOpenlist)[++ind];
+ }
+ if (p != NULL) pOpenlist->erase(ind);
+ switch (QMessageBox::information ( this , PROGNAME, "What do you want to delete?", "Nothing", "Marks", "Marks\nFile", 1, 0 ))
+ {
+ case 0:
+ default:
+ break;
+ case 2:
+ unlink((const char*)reader->m_lastfile);
+ case 1:
+ unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
+ }
+ }
+
+ fileOpen2();
+}
+
+void QTReaderApp::updatefileinfo()
+{
+ if (reader->m_string.isNull()) return;
+ if (reader->m_lastfile.isNull()) return;
+ tchar* nm = fromQString(reader->m_string);
+ tchar* fl = fromQString(reader->m_lastfile);
+ qDebug("Lastfile:%x", fl);
+ bool notadded = true;
+ if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>;
+ else
+ {
+ for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
+ {
+ if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0)
+ {
+ iter->value(reader->pagelocate());
+ unsigned short dlen;
+ unsigned char* data;
+ CFiledata fd(iter->anno());
+ reader->setSaveData(data, dlen, fd.content(), fd.length());
+ qDebug("Filedata(1):%u, %u", fd.length(), dlen);
+// getstate(data, dlen);
+ iter->setAnno(data, dlen);
+ notadded = false;
+ delete [] data;
+ break;
+ }
+ }
+ }
+ qDebug("Added?:%x", notadded);
+ if (notadded)
+ {
+ struct stat fnstat;
+ stat((const char *)reader->m_lastfile, &fnstat);
+ CFiledata fd(fnstat.st_mtime, fl);
+ unsigned short dlen;
+ unsigned char* data;
+ reader->setSaveData(data, dlen, fd.content(), fd.length());
+ pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate()));
+ qDebug("Filedata(2):%u, %u", fd.length(), dlen);
+ delete [] data;
+ }
+ delete [] nm;
+ delete [] fl;
}
void QTReaderApp::fileOpen()
@@ -937,35 +1169,69 @@ void QTReaderApp::fileOpen()
if (regVisible) regBar->hide();
if (searchVisible) searchBar->hide();
*/
+ qDebug("fileOpen");
+// if (!reader->m_lastfile.isEmpty())
+ updatefileinfo();
+ fileOpen2();
+}
+
+void QTReaderApp::fileOpen2()
+{
if (pBkmklist != NULL)
{
- if (m_fBkmksChanged)
- {
- if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0)
- savebkmks();
- }
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
+ if (m_fBkmksChanged)
+ {
+ if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
+ savebkmks();
+ }
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
}
reader->disableAutoscroll();
/*
editorStack->raiseWidget( fileSelector );
fileSelector->reread();
*/
- fileBrowser* fb = new fileBrowser(this,"OpieReader",TRUE,
- 0,
-// WStyle_Customize | WStyle_NoBorderEx,
- "*", QFileInfo(reader->m_lastfile).dirPath(true));
+ if (pOpenlist != NULL)
+ {
+ m_nRegAction = cOpenFile;
+ listbkmk(pOpenlist, "Browse");
+ }
+ else
+ {
+ QString fn = usefilebrowser();
+ if (!fn.isEmpty() && QFileInfo(fn).isFile())
+ {
+ openFile(fn);
+ }
+ reader->setFocus();
+ }
+}
+
+QString QTReaderApp::usefilebrowser()
+{
+ fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE,
+ 0,
+// WStyle_Customize | WStyle_NoBorderEx,
+ "*", QFileInfo(reader->m_lastfile).dirPath(true));
+
+ QString fn;
if (fb->exec())
{
- QString fn(fb->fileList[0]);
-// fb->populateList();
- if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
+ fn = fb->fileList[0];
}
+ qDebug("Selected %s", (const char*)fn);
delete fb;
- reader->setFocus();
+ return fn;
+}
+
+void QTReaderApp::showgraphic(QPixmap& pm)
+{
+ m_graphicwin->setPixmap(pm);
+ editorStack->raiseWidget( m_graphicwin );
+ m_graphicwin->setFocus();
}
void QTReaderApp::showinfo()
@@ -973,19 +1239,19 @@ void QTReaderApp::showinfo()
unsigned long fs, ts, pl;
if (reader->empty())
{
- QMessageBox::information(this, "OpieReader", "No file loaded", 1);
+ QMessageBox::information(this, PROGNAME, "No file loaded", 1);
}
else
{
- reader->sizes(fs,ts);
- pl = reader->pagelocate();
- m_infoWin->setFileSize(fs);
- m_infoWin->setTextSize(ts);
- m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
- m_infoWin->setLocation(pl);
- m_infoWin->setRead((100*pl + (ts >> 1))/ts);
- editorStack->raiseWidget( m_infoWin );
- m_infoWin->setFocus();
+ reader->sizes(fs,ts);
+ pl = reader->pagelocate();
+ m_infoWin->setFileSize(fs);
+ m_infoWin->setTextSize(ts);
+ m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
+ m_infoWin->setLocation(pl);
+ m_infoWin->setRead((100*pl + (ts >> 1))/ts);
+ editorStack->raiseWidget( m_infoWin );
+ m_infoWin->setFocus();
}
}
@@ -997,13 +1263,13 @@ void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn)
int i;
for (i = 0; i < name.length(); i++)
{
- buff[i] = name[i].unicode();
+ buff[i] = name[i].unicode();
}
buff[i] = 0;
CBuffer buff2(text.length()+1);
for (i = 0; i < text.length(); i++)
{
- buff2[i] = text[i].unicode();
+ buff2[i] = text[i].unicode();
}
buff2[i] = 0;
pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn));
@@ -1018,40 +1284,40 @@ void QTReaderApp::addAnno(const QString& name, const QString& text)
{
if (m_annoIsEditing)
{
- if (name.isEmpty())
- {
- QMessageBox::information(this, "OpieReader", "Need a name for the bookmark\nPlease try again", 1);
- }
- else
- {
- addAnno(name, text, m_annoWin->getPosn());
- }
- showEditTools();
+ if (name.isEmpty())
+ {
+ QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1);
+ }
+ else
+ {
+ addAnno(name, text, m_annoWin->getPosn());
+ }
+ showEditTools();
}
else
{
- if (m_annoWin->edited())
- {
- CBuffer buff(text.length()+1);
- int i;
- for (i = 0; i < text.length(); i++)
- {
- buff[i] = text[i].unicode();
- }
- buff[i] = 0;
- m_fBkmksChanged = true;
- m_anno->setAnno(buff.data());
- }
- bool found = findNextBookmark(m_anno->value()+1);
- if (found)
- {
- m_annoWin->setName(toQString(m_anno->name()));
- m_annoWin->setAnno(toQString(m_anno->anno()));
- }
- else
- {
- showEditTools();
- }
+ if (m_annoWin->edited())
+ {
+ CBuffer buff(text.length()+1);
+ int i;
+ for (i = 0; i < text.length(); i++)
+ {
+ buff[i] = text[i].unicode();
+ }
+ buff[i] = 0;
+ m_fBkmksChanged = true;
+ m_anno->setAnno(buff.data());
+ }
+ bool found = findNextBookmark(m_anno->value()+1);
+ if (found)
+ {
+ m_annoWin->setName(toQString(m_anno->name()));
+ m_annoWin->setAnno(toQString(m_anno->anno()));
+ }
+ else
+ {
+ showEditTools();
+ }
}
}
@@ -1060,15 +1326,15 @@ bool QTReaderApp::findNextBookmark(size_t start)
bool found = false;
for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
{
- if (iter->value() >= start)
- {
- if (iter->value() < reader->locate())
- {
- found = true;
- m_anno = iter.pContent();
- }
- break;
- }
+ if (iter->value() >= start)
+ {
+ if (iter->value() < reader->locate())
+ {
+ found = true;
+ m_anno = iter.pContent();
+ }
+ break;
+ }
}
return found;
}
@@ -1077,16 +1343,17 @@ void QTReaderApp::addanno()
{
if (reader->empty())
{
- QMessageBox::information(this, "OpieReader", "No file loaded", 1);
+ QMessageBox::information(this, PROGNAME, "No file loaded", 1);
}
else
{
- m_annoWin->setName("");
- m_annoWin->setAnno("");
- m_annoWin->setPosn(reader->pagelocate());
- m_annoIsEditing = true;
- editorStack->raiseWidget( m_annoWin );
- m_annoWin->setFocus();
+ m_annoWin->setName("");
+ m_annoWin->setAnno("");
+ m_annoWin->setPosn(reader->pagelocate());
+ m_annoIsEditing = true;
+ editorStack->raiseWidget( m_annoWin );
+ Global::showInputMethod();
+ m_annoWin->setFocus();
}
}
@@ -1116,34 +1383,44 @@ void QTReaderApp::editMark()
void QTReaderApp::editCopy()
{
- QClipboard* cb = QApplication::clipboard();
- QString text;
- int ch;
- unsigned long currentpos = reader->pagelocate();
- unsigned long endpos = reader->locate();
- reader->jumpto(m_savedpos);
- while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
- {
- text += ch;
- }
- cb->setText(text);
- reader->locate(currentpos);
+ QClipboard* cb = QApplication::clipboard();
+ QString text;
+ int ch;
+ unsigned long currentpos = reader->pagelocate();
+ unsigned long endpos = reader->locate();
+ reader->jumpto(m_savedpos);
+ while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
+ {
+ text += ch;
+ }
+ cb->setText(text);
+ reader->locate(currentpos);
}
void QTReaderApp::pageup()
{
- reader->goUp();
+ reader->NavUp();
}
void QTReaderApp::pagedn()
{
- reader->goDown();
+ reader->NavDown();
}
void QTReaderApp::stripcr(bool _b)
{
reader->setstripcr(_b);
}
+void QTReaderApp::onespace(bool _b)
+{
+ reader->setonespace(_b);
+}
+#ifdef REPALM
+void QTReaderApp::repalm(bool _b)
+{
+ reader->setrepalm(_b);
+}
+#endif
void QTReaderApp::remap(bool _b)
{
reader->setremap(_b);
@@ -1188,7 +1465,10 @@ void QTReaderApp::pagemode(bool _b)
{
reader->setpagemode(_b);
}
-
+void QTReaderApp::navkeys(bool _b)
+{
+ reader->m_navkeys = _b;
+}
void QTReaderApp::monospace(bool _b)
{
reader->setmono(_b);
@@ -1216,8 +1496,8 @@ void QTReaderApp::settarget()
{
m_nRegAction = cSetTarget;
QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
- + "/"
- + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
+ + "/"
+ + ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
regEdit->setText(text);
do_regedit();
}
@@ -1228,10 +1508,10 @@ void QTReaderApp::do_overlap(const QString& lcn)
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
- reader->m_overlap = ulcn;
+ reader->m_overlap = ulcn;
}
else
- QMessageBox::information(this, "OpieReader", "Must be a number");
+ QMessageBox::information(this, PROGNAME, "Must be a number");
}
void QTReaderApp::do_mono(const QString& lcn)
@@ -1240,13 +1520,13 @@ void QTReaderApp::do_mono(const QString& lcn)
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
- reader->m_charpc = ulcn;
- reader->setfont();
- reader->refresh();
-// reader->setmono(true);
+ reader->m_charpc = ulcn;
+ reader->setfont();
+ reader->refresh();
+// reader->setmono(true);
}
else
- QMessageBox::information(this, "OpieReader", "Must be a number");
+ QMessageBox::information(this, PROGNAME, "Must be a number");
}
/*
@@ -1264,6 +1544,7 @@ void QTReaderApp::editFind()
#ifdef __ISEARCH
searchStack = new QStack<searchrecord>;
#endif
+ Global::showInputMethod();
searchBar->show();
searchVisible = TRUE;
searchEdit->setFocus();
@@ -1291,6 +1572,7 @@ void QTReaderApp::findClose()
{
searchVisible = FALSE;
searchEdit->setText("");
+ Global::hideInputMethod();
searchBar->hide();
#ifdef __ISEARCH
// searchStack = new QStack<searchrecord>;
@@ -1308,6 +1590,7 @@ void QTReaderApp::regClose()
regVisible = FALSE;
regEdit->setText("");
regBar->hide();
+ Global::hideInputMethod();
reader->setFocus();
}
@@ -1318,8 +1601,17 @@ bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
#endif
{
bool ret = true;
+ unsigned long fs, ts;
+ reader->sizes(fs,ts);
size_t pos = reader->locate();
reader->buffdoc.getline(&test,reader->width());
+ pbar->show();
+ pbar->resize(width(), editBar->height());
+ pbar->reset();
+ int lastpc = (100*pos)/ts;
+ pbar->setProgress(lastpc);
+ qApp->processEvents();
+ reader->setFocus();
#ifdef __ISEARCH
while (strstr(test.data(),(const tchar*)arg) == NULL)
#else
@@ -1331,17 +1623,28 @@ bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
#endif
{
pos = reader->locate();
+ unsigned int lcn = reader->locate();
+ int pc = (100*pos)/ts;
+ if (pc != lastpc)
+ {
+ pbar->setProgress(pc);
+ qApp->processEvents();
+ reader->setFocus();
+ lastpc = pc;
+ }
+
if (!reader->buffdoc.getline(&test,reader->width()))
- {
- if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
- pos = searchStart;
- else
- pos = start;
- ret = false;
- findClose();
- break;
- }
+ {
+ if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
+ pos = searchStart;
+ else
+ pos = start;
+ ret = false;
+ findClose();
+ break;
+ }
}
+ pbar->hide();
reader->locate(pos);
return ret;
}
@@ -1388,83 +1691,151 @@ void QTReaderApp::search()
void QTReaderApp::openFile( const QString &f )
{
- openFile(DocLnk(f));
-}
-
-void QTReaderApp::openFile( const DocLnk &f )
-{
+ qDebug("File:%s", (const char*)f);
+// openFile(DocLnk(f));
+//}
+//
+//void QTReaderApp::openFile( const DocLnk &f )
+//{
clear();
- FileManager fm;
- if ( fm.exists( f ) )
+ QFileInfo fm(f);
+ if ( fm.exists() )
{
// QMessageBox::information(0, "Progress", "Calling fileNew()");
- clear();
+ if (fm.extension( FALSE ) == "desktop")
+ {
+ DocLnk d(f);
+ QFileInfo fnew(d.file());
+ fm = fnew;
+ if (!fm.exists()) return;
+ }
- // editorStack->raiseWidget( reader );
-
- // reader->setFocus();
-
- // QMessageBox::information(0, "DocLnk", "Begin");
- doc = new DocLnk(f);
- // QMessageBox::information(0, "DocLnk done", doc->file());
- // QMessageBox::information(0, "Progress", "Calling setText()");
- // QMessageBox::information(0, "Progress", "Textset");
+ clear();
- // updateCaption();
+ reader->setText(fm.baseName(), fm.absFilePath());
showEditTools();
- reader->setText(doc->name(), doc->file());
readbkmks();
}
else
{
- QMessageBox::information(this, "OpieReader", "File does not exist");
+ QMessageBox::information(this, PROGNAME, "File does not exist");
+ }
+
+}
+/*
+void QTReaderApp::resizeEvent(QResizeEvent* e)
+{
+ if (m_fullscreen)
+ {
+ showNormal();
+ showFullScreen();
+ }
+}
+*/
+void QTReaderApp::keyPressEvent(QKeyEvent* e)
+{
+ if (m_fullscreen)
+ {
+ switch(e->key())
+ {
+ case Key_Escape:
+ m_actFullscreen->setOn(false);
+ if (m_fullscreen)
+ {
+ qDebug("Fullscreen already set - remove this!");
+ }
+ else
+ {
+ m_fullscreen = false;
+ reader->bDoUpdates = false;
+ showEditTools();
+ qApp->processEvents();
+ reader->bDoUpdates = true;
+ reader->update();
+ }
+ e->accept();
+ break;
+ default:
+ e->ignore();
+ }
+ }
+ else
+ {
+ e->ignore();
}
-
}
void QTReaderApp::showEditTools()
{
- if ( !doc )
- close();
-// fileSelector->hide();
-//tjw menu->show();
- editBar->show();
- if ( searchVisible )
- searchBar->show();
- if ( regVisible )
- regBar->show();
- if (m_fontVisible) m_fontBar->show();
-
+// if ( !doc )
+// close();
+ if (m_fullscreen)
+ {
+ editBar->hide();
+ searchBar->hide();
+ regBar->hide();
+ Global::hideInputMethod();
+ m_fontBar->hide();
+// showNormal();
+ showFullScreen();
+ }
+ else
+ {
+ qDebug("him");
+ Global::hideInputMethod();
+ qDebug("eb");
+ editBar->show();
+ if ( searchVisible )
+ {
+ Global::showInputMethod();
+ searchBar->show();
+ }
+ if ( regVisible )
+ {
+ Global::showInputMethod();
+ regBar->show();
+ }
+ if (m_fontVisible) m_fontBar->show();
+ qDebug("sn");
+ showNormal();
+ qDebug("sm");
+ showMaximized();
+// setCentralWidget(reader);
+ }
+
+ qDebug("uc");
updateCaption();
+ qDebug("rw");
editorStack->raiseWidget( reader );
+ qDebug("sf");
reader->setFocus();
}
/*
void QTReaderApp::save()
{
if ( !doc )
- return;
+ return;
if ( !editor->edited() )
- return;
+ return;
QString rt = editor->text();
QString pt = rt;
if ( doc->name().isEmpty() ) {
- unsigned ispace = pt.find( ' ' );
- unsigned ienter = pt.find( '\n' );
- int i = (ispace < ienter) ? ispace : ienter;
- QString docname;
- if ( i == -1 ) {
- if ( pt.isEmpty() )
- docname = "Empty Text";
- else
- docname = pt;
- } else {
- docname = pt.left( i );
- }
- doc->setName(docname);
+ unsigned ispace = pt.find( ' ' );
+ unsigned ienter = pt.find( '\n' );
+ int i = (ispace < ienter) ? ispace : ienter;
+ QString docname;
+ if ( i == -1 ) {
+ if ( pt.isEmpty() )
+ docname = "Empty Text";
+ else
+ docname = pt;
+ } else {
+ docname = pt.left( i );
+ }
+ doc->setName(docname);
}
FileManager fm;
fm.saveFile( *doc, rt );
@@ -1473,121 +1844,143 @@ void QTReaderApp::save()
void QTReaderApp::clear()
{
- if (doc != 0)
- {
-// QMessageBox::information(this, "QTReader", "Deleting doc", 1);
- delete doc;
-// QMessageBox::information(this, "QTReader", "Deleted doc", 1);
- doc = 0;
- }
+// if (doc != 0)
+// {
+// QMessageBox::information(this, PROGNAME, "Deleting doc", 1);
+// delete doc;
+// QMessageBox::information(this, PROGNAME, "Deleted doc", 1);
+// doc = 0;
+ // }
reader->clear();
}
void QTReaderApp::updateCaption()
{
- if ( !doc )
- setCaption( tr("OpieReader") );
- else {
- QString s = doc->name();
- if ( s.isEmpty() )
- s = tr( "Unnamed" );
- setCaption( s + " - " + tr("OpieReader") );
- }
+// if ( !doc )
+// setCaption( tr("QTReader") );
+// else {
+// QString s = doc->name();
+// if ( s.isEmpty() )
+// s = tr( "Unnamed" );
+ setCaption( reader->m_string + " - " + tr(SHORTPROGNAME) );
+// }
}
void QTReaderApp::setDocument(const QString& fileref)
{
bFromDocView = TRUE;
//QMessageBox::information(0, "setDocument", fileref);
- openFile(DocLnk(fileref));
+ openFile(fileref);
// showEditTools();
}
void QTReaderApp::closeEvent( QCloseEvent *e )
{
- if (m_dontSave)
+ if (m_fullscreen)
{
- e->accept();
+ m_fullscreen = false;
+ showEditTools();
+ e->accept();
+ }
+ else if (m_dontSave)
+ {
+ e->accept();
}
else
{
- if (editorStack->visibleWidget() == reader)
- {
- if (m_fontVisible)
- {
- m_fontBar->hide();
- m_fontVisible = false;
- }
- if (regVisible)
- {
- regBar->hide();
- regVisible = false;
- return;
- }
- if (searchVisible)
- {
- searchBar->hide();
- searchVisible = false;
- return;
- }
- if (m_fBkmksChanged && pBkmklist != NULL)
- {
- if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0)
- savebkmks();
- delete pBkmklist;
- pBkmklist = NULL;
- m_fBkmksChanged = false;
- }
- bFromDocView = FALSE;
- saveprefs();
- e->accept();
- }
- else
- {
- showEditTools();
- }
+ if (editorStack->visibleWidget() == reader)
+ {
+ if (m_fontVisible)
+ {
+ m_fontBar->hide();
+ m_fontVisible = false;
+ }
+ if (regVisible)
+ {
+ regBar->hide();
+ Global::hideInputMethod();
+ regVisible = false;
+ return;
+ }
+ if (searchVisible)
+ {
+ searchBar->hide();
+ Global::hideInputMethod();
+ searchVisible = false;
+ return;
+ }
+ if (m_fBkmksChanged && pBkmklist != NULL)
+ {
+ if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
+ savebkmks();
+ delete pBkmklist;
+ pBkmklist = NULL;
+ m_fBkmksChanged = false;
+ }
+ bFromDocView = FALSE;
+ updatefileinfo();
+ saveprefs();
+ e->accept();
+ }
+ else
+ {
+ showEditTools();
+ }
}
}
void QTReaderApp::do_gotomark()
{
m_nRegAction = cGotoBkmk;
- listbkmk();
+ listbkmk(pBkmklist);
}
void QTReaderApp::do_delmark()
{
m_nRegAction = cDelBkmk;
- listbkmk();
+ listbkmk(pBkmklist);
}
-void QTReaderApp::listbkmk()
+void QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab)
{
bkmkselector->clear();
+ if (_lab.isNull())
+ bkmkselector->setText("Cancel");
+ else
+ bkmkselector->setText(_lab);
int cnt = 0;
- if (pBkmklist != NULL)
+ if (plist != NULL)
{
- for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++)
- {
+ for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++)
+ {
#ifdef _UNICODE
- bkmkselector->insertItem(toQString(i->name()));
+ qDebug("Item:%s", (const char*)toQString(i->name()));
+ bkmkselector->insertItem(toQString(i->name()));
#else
- bkmkselector->insertItem(i->name());
+ bkmkselector->insertItem(i->name());
#endif
- cnt++;
- }
+ cnt++;
+ }
}
if (cnt > 0)
{
//tjw menu->hide();
editBar->hide();
if (m_fontVisible) m_fontBar->hide();
- if (regVisible) regBar->hide();
- if (searchVisible) searchBar->hide();
+ if (regVisible)
+ {
+ Global::hideInputMethod();
+ regBar->hide();
+ }
+ if (searchVisible)
+ {
+ Global::hideInputMethod();
+ searchBar->hide();
+ }
editorStack->raiseWidget( bkmkselector );
}
else
- QMessageBox::information(this, "OpieReader", "No bookmarks in memory");
+ QMessageBox::information(this, PROGNAME, "No bookmarks in memory");
}
void QTReaderApp::do_autogen()
@@ -1600,33 +1993,95 @@ void QTReaderApp::do_autogen()
void QTReaderApp::do_regedit()
{
// editBar->hide();
+ reader->bDoUpdates = false;
+ qDebug("Showing regbar");
regBar->show();
+ qDebug("Showing kbd");
+ Global::showInputMethod();
regVisible = true;
regEdit->setFocus();
+ qApp->processEvents();
+ reader->bDoUpdates = true;
+ reader->update();
+}
+
+bool QTReaderApp::openfrombkmk(Bkmk* bk)
+{
+ QString fn = toQString(
+ CFiledata(bk->anno()).name()
+ );
+ qDebug("fileinfo");
+ if (!fn.isEmpty() && QFileInfo(fn).isFile())
+ {
+ qDebug("Opening");
+ openFile(fn);
+ struct stat fnstat;
+ stat((const char *)reader->m_lastfile, &fnstat);
+
+ if (CFiledata(bk->anno()).date()
+ != fnstat.st_mtime)
+ {
+ CFiledata fd(bk->anno());
+ fd.setdate(fnstat.st_mtime);
+ bk->value(0);
+ }
+ else
+ {
+ unsigned short svlen = bk->filedatalen();
+ unsigned char* svdata = bk->filedata();
+ reader->putSaveData(svdata, svlen);
+// setstate(svdata, svlen);
+ if (svlen != 0)
+ {
+ QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?");
+ }
+ qDebug("updating");
+ reader->locate(bk->value());
+ }
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
void QTReaderApp::gotobkmk(int ind)
{
switch (m_nRegAction)
{
- case cGotoBkmk:
- reader->locate((*pBkmklist)[ind]->value());
- break;
- case cDelBkmk:
-// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
- pBkmklist->erase(ind);
- m_fBkmksChanged = true;
-// pBkmklist->sort();
- break;
- case cRmBkmkFile:
- unlink((const char *)Global::applicationFileName("uqtreader",bkmkselector->text(ind)));
- break;
+ case cOpenFile:
+ {
+ if (!openfrombkmk((*pOpenlist)[ind]))
+ {
+ pOpenlist->erase(ind);
+ QMessageBox::information(this, PROGNAME, "Can't find file");
+ }
+ }
+ break;
+ case cGotoBkmk:
+ reader->locate((*pBkmklist)[ind]->value());
+ break;
+ case cDelBkmk:
+// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
+ pBkmklist->erase(ind);
+ m_fBkmksChanged = true;
+// pBkmklist->sort();
+ break;
+ case cRmBkmkFile:
+ unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind)));
+ break;
}
showEditTools();
}
void QTReaderApp::cancelbkmk()
{
+ if (m_nRegAction == cOpenFile)
+ {
+ QString fn = usefilebrowser();
+ if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
+ }
showEditTools();
}
@@ -1644,39 +2099,44 @@ void QTReaderApp::do_jump(const QString& lcn)
bool ok;
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
- reader->locate(ulcn);
+ reader->locate(ulcn);
else
- QMessageBox::information(this, "OpieReader", "Must be a number");
+ QMessageBox::information(this, PROGNAME, "Must be a number");
}
void QTReaderApp::do_regaction()
{
+ reader->bDoUpdates = false;
regBar->hide();
+ Global::hideInputMethod();
regVisible = false;
switch(m_nRegAction)
{
case cAutoGen:
- do_autogen(regEdit->text());
- break;
+ do_autogen(regEdit->text());
+ break;
case cAddBkmk:
- do_addbkmk(regEdit->text());
- break;
+ do_addbkmk(regEdit->text());
+ break;
case cJump:
- do_jump(regEdit->text());
- break;
+ do_jump(regEdit->text());
+ break;
case cMonoSpace:
- do_mono(regEdit->text());
- break;
+ do_mono(regEdit->text());
+ break;
case cOverlap:
- do_overlap(regEdit->text());
- break;
+ do_overlap(regEdit->text());
+ break;
case cSetTarget:
- do_settarget(regEdit->text());
- break;
+ do_settarget(regEdit->text());
+ break;
}
reader->restore();
// editBar->show();
reader->setFocus();
+ qApp->processEvents();
+ reader->bDoUpdates = true;
+ reader->update();
}
void QTReaderApp::do_settarget(const QString& _txt)
@@ -1684,14 +2144,14 @@ void QTReaderApp::do_settarget(const QString& _txt)
int ind = _txt.find('/');
if (ind == -1)
{
- m_targetapp = "";
- m_targetmsg = "";
- QMessageBox::information(this, "OpieReader", "Format is\nappname/messagename");
+ m_targetapp = "";
+ m_targetmsg = "";
+ QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename");
}
else
{
- m_targetapp = _txt.left(ind);
- m_targetmsg = _txt.right(_txt.length()-ind-1);
+ m_targetapp = _txt.left(ind);
+ m_targetmsg = _txt.right(_txt.length()-ind-1);
}
}
@@ -1699,33 +2159,42 @@ void QTReaderApp::setfont()
{
for (int i = 1; i <= m_fontSelector->count(); i++)
{
- if (m_fontSelector->text(i) == reader->m_fontname)
- {
- m_fontSelector->setCurrentItem(i);
- break;
- }
+ if (m_fontSelector->text(i) == reader->m_fontname)
+ {
+ m_fontSelector->setCurrentItem(i);
+ break;
+ }
}
m_fontBar->show();
m_fontVisible = true;
}
-void QTReaderApp::setfontHelper(const QString& lcn, int size)
+void QTReaderApp::setfontHelper(const QString& lcn, int size = 0)
{
if (size == 0) size = reader->m_fontControl.currentsize();
QFont f(lcn, 10 /*, QFont::Bold*/);
+ qDebug("bs");
bkmkselector->setFont( f );
+ qDebug("re");
regEdit->setFont( f );
+ qDebug("se");
searchEdit->setFont( f );
+ qDebug("aw");
m_annoWin->setFont( f );
reader->m_fontname = lcn;
+ qDebug("cf1");
if (!reader->ChangeFont(size))
{
- reader->ChangeFont(size);
+ qDebug("cf2");
+ reader->ChangeFont(size);
}
+ qDebug("ref");
reader->refresh();
m_fontBar->hide();
m_fontVisible = false;
- showEditTools();
+ qDebug("showedit");
+ if (reader->isVisible()) showEditTools();
+ qDebug("showeditdone");
}
void QTReaderApp::do_setfont(const QString& lcn)
@@ -1759,9 +2228,9 @@ pbar->resize(width(), editBar->height());
if (pc != lastpc)
{
pbar->setProgress(pc);
- qApp->processEvents();
- if (reader->locate() != lcn) reader->jumpto(lcn);
- reader->setFocus();
+ qApp->processEvents();
+ if (reader->locate() != lcn) reader->jumpto(lcn);
+ reader->setFocus();
lastpc = pc;
}
i = reader->buffdoc.getpara(buff);
@@ -1770,7 +2239,7 @@ pbar->resize(width(), editBar->height());
#else
if (re.match(buff.data()) != -1)
#endif
- pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
+ pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
}
pBkmklist->sort();
pbar->setProgress(100);
@@ -1781,7 +2250,7 @@ pbar->resize(width(), editBar->height());
void QTReaderApp::saveprefs()
{
// reader->saveprefs("uqtreader");
- Config config( "uqtreader" );
+ Config config( APPDIR );
config.setGroup( "View" );
reader->m_lastposn = reader->pagelocate();
@@ -1791,6 +2260,7 @@ void QTReaderApp::saveprefs()
config.writeEntry( "TextFmt", reader->btextfmt );
config.writeEntry( "StripHtml", reader->bstriphtml );
config.writeEntry( "Dehyphen", reader->bdehyphen );
+ config.writeEntry( "OneSpace", reader->bonespace );
config.writeEntry( "Unindent", reader->bunindent );
config.writeEntry( "Repara", reader->brepara );
config.writeEntry( "DoubleSpace", reader->bdblspce );
@@ -1800,6 +2270,7 @@ void QTReaderApp::saveprefs()
config.writeEntry( "LastFile", reader->m_lastfile );
config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
config.writeEntry( "PageMode", reader->m_bpagemode );
+ config.writeEntry( "CursorNavigation", reader->m_navkeys );
config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced );
config.writeEntry( "Fontname", reader->m_fontname );
config.writeEntry( "Encoding", reader->m_encd );
@@ -1812,9 +2283,15 @@ void QTReaderApp::saveprefs()
config.writeEntry( "Dictionary", m_doDictionary);
config.writeEntry( "Clipboard", m_doClipboard);
config.writeEntry( "SpaceTarget", m_spaceTarget);
+#ifdef REPALM
+ config.writeEntry( "Repalm", reader->brepalm );
+#endif
config.writeEntry( "Remap", reader->bremap );
config.writeEntry( "Peanut", reader->bpeanut );
config.writeEntry( "MakeBold", reader->bmakebold );
+ config.writeEntry( "Continuous", reader->m_continuousDocument );
+
+ savefilelist();
}
void QTReaderApp::indentplus()
@@ -1844,40 +2321,40 @@ void info_cb(Fl_Widget* o, void* _data)
if (infowin == NULL)
{
-
- infowin = new Fl_Window(160,240);
- filename = new Fl_Output(45,5,110,14,"Filename");
- filesize = new Fl_Output(45,25,110,14,"Filesize");
- textsize = new Fl_Output(45,45,110,14,"Textsize");
- comprat = new CBar(45,65,110,14,"Ratio %");
- posn = new Fl_Output(45,85,110,14,"Location");
- frcn = new CBar(45,105,110,14,"% Read");
- about = new Fl_Multiline_Output(5,125,150,90);
- about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
- Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
- infowin->set_modal();
+
+ infowin = new Fl_Window(160,240);
+ filename = new Fl_Output(45,5,110,14,"Filename");
+ filesize = new Fl_Output(45,25,110,14,"Filesize");
+ textsize = new Fl_Output(45,45,110,14,"Textsize");
+ comprat = new CBar(45,65,110,14,"Ratio %");
+ posn = new Fl_Output(45,85,110,14,"Location");
+ frcn = new CBar(45,105,110,14,"% Read");
+ about = new Fl_Multiline_Output(5,125,150,90);
+ about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
+ Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
+ infowin->set_modal();
}
if (((reader_ui *)_data)->g_filename[0] != '\0')
{
- unsigned long fs,ts;
- tchar sz[20];
- ((reader_ui *)_data)->input->sizes(fs,ts);
- unsigned long pl = ((reader_ui *)_data)->input->locate();
+ unsigned long fs,ts;
+ tchar sz[20];
+ ((reader_ui *)_data)->input->sizes(fs,ts);
+ unsigned long pl = ((reader_ui *)_data)->input->locate();
- filename->value(((reader_ui *)_data)->g_filename);
+ filename->value(((reader_ui *)_data)->g_filename);
- sprintf(sz,"%u",fs);
- filesize->value(sz);
+ sprintf(sz,"%u",fs);
+ filesize->value(sz);
- sprintf(sz,"%u",ts);
- textsize->value(sz);
+ sprintf(sz,"%u",ts);
+ textsize->value(sz);
- comprat->value(100-(100*fs + (ts >> 1))/ts);
+ comprat->value(100-(100*fs + (ts >> 1))/ts);
- sprintf(sz,"%u",pl);
- posn->value(sz);
+ sprintf(sz,"%u",pl);
+ posn->value(sz);
- frcn->value((100*pl + (ts >> 1))/ts);
+ frcn->value((100*pl + (ts >> 1))/ts);
}
infowin->show();
}
@@ -1887,27 +2364,61 @@ void QTReaderApp::savebkmks()
{
if (pBkmklist != NULL)
{
- BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string), true);
- bf.write(*pBkmklist);
+ BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string), true);
+ bf.write(*pBkmklist);
+ }
+ m_fBkmksChanged = false;
+}
+
+void QTReaderApp::readfilelist()
+{
+ BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"));
+ qDebug("Reading open files");
+ pOpenlist = bf.readall();
+ if (pOpenlist != NULL) qDebug("...with success");
+ else qDebug("...without success!");
+}
+
+void QTReaderApp::savefilelist()
+{
+ if (pOpenlist != NULL)
+ {
+ BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"), true);
+ qDebug("Writing open files");
+ bf.write(*pOpenlist);
}
- m_fBkmksChanged = false;
}
void QTReaderApp::readbkmks()
{
if (pBkmklist != NULL)
{
- delete pBkmklist;
+ delete pBkmklist;
+ }
+ struct stat fnstat;
+ struct stat bkstat;
+ if (
+ stat((const char *)reader->m_lastfile, &fnstat) == 0
+ &&
+ stat((const char *)Global::applicationFileName(APPDIR, reader->m_string), &bkstat) == 0
+ )
+ {
+ if (bkstat.st_mtime < fnstat.st_mtime)
+ {
+ unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
+ }
}
- BkmkFile bf((const char *)Global::applicationFileName("uqtreader",reader->m_string));
+
+ BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string));
+
pBkmklist = bf.readall();
m_fBkmksChanged = bf.upgraded();
if (pBkmklist == NULL)
{
- pBkmklist = reader->getbkmklist();
+ pBkmklist = reader->getbkmklist();
}
if (pBkmklist != NULL)
- pBkmklist->sort();
+ pBkmklist->sort();
}
void QTReaderApp::addbkmk()
@@ -1919,36 +2430,36 @@ void QTReaderApp::addbkmk()
void QTReaderApp::do_addbkmk(const QString& text)
{
- if (text.isEmpty())
- {
- QMessageBox::information(this, "OpieReader", "Need a name for the bookmark\nSelect add again", 1);
- }
- else
- {
- if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
+ if (text.isEmpty())
+ {
+ QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1);
+ }
+ else
+ {
+ if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
#ifdef _UNICODE
- CBuffer buff;
- int i = 0;
- for (i = 0; i < text.length(); i++)
- {
- buff[i] = text[i].unicode();
- }
- buff[i] = 0;
- pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
+ CBuffer buff;
+ int i = 0;
+ for (i = 0; i < text.length(); i++)
+ {
+ buff[i] = text[i].unicode();
+ }
+ buff[i] = 0;
+ pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
#else
- pBkmklist->push_front(Bkmk((const tchar*)text,reader->pagelocate()));
+ pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate()));
#endif
- m_fBkmksChanged = true;
- pBkmklist->sort();
- }
+ m_fBkmksChanged = true;
+ pBkmklist->sort();
+ }
}
void QTReaderApp::OnRedraw()
{
if (pBkmklist != NULL)
{
- bool found = findNextBookmark(reader->pagelocate());
- m_bkmkAvail->setEnabled(found);
+ bool found = findNextBookmark(reader->pagelocate());
+ m_bkmkAvail->setEnabled(found);
}
}
@@ -1957,6 +2468,7 @@ void QTReaderApp::showAnnotation()
m_annoWin->setName(toQString(m_anno->name()));
m_annoWin->setAnno(toQString(m_anno->anno()));
m_annoIsEditing = false;
+ Global::showInputMethod();
editorStack->raiseWidget( m_annoWin );
m_annoWin->setFocus();
}
@@ -1967,33 +2479,34 @@ void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString&
if (m_doClipboard)
{
- QClipboard* cb = QApplication::clipboard();
- cb->setText(wrd);
- if (wrd.length() > 10)
- {
- Global::statusMessage(wrd.left(8) + "..");
- }
- else
- {
- Global::statusMessage(wrd);
- }
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(wrd);
+ if (wrd.length() > 10)
+ {
+ Global::statusMessage(wrd.left(8) + "..");
+ }
+ else
+ {
+ Global::statusMessage(wrd);
+ }
}
if (m_doAnnotation)
{
-// addAnno(wrd, "Need to be able to edit this", posn);
- m_annoWin->setName(line);
- m_annoWin->setAnno("");
- m_annoWin->setPosn(posn);
- m_annoIsEditing = true;
- editorStack->raiseWidget( m_annoWin );
+// addAnno(wrd, "Need to be able to edit this", posn);
+ m_annoWin->setName(line);
+ m_annoWin->setAnno("");
+ m_annoWin->setPosn(posn);
+ m_annoIsEditing = true;
+ Global::showInputMethod();
+ editorStack->raiseWidget( m_annoWin );
}
if (m_doDictionary)
{
- if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
- {
- QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
- e << wrd;
- }
+ if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
+ {
+ QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
+ e << wrd;
+ }
}
}
@@ -2001,29 +2514,93 @@ void QTReaderApp::OnActionPressed()
{
switch (m_spaceTarget)
{
- case cesOpenFile:
- {
- fileOpen();
- }
- break;
- case cesAutoScroll:
- {
- reader->setautoscroll(!reader->m_autoScroll);
- setScrollState(reader->m_autoScroll);
- }
- break;
- case cesActionMark:
- {
- addbkmk();
- }
- break;
- default:
- {
- qDebug("Unknown ActionType:%u", m_spaceTarget);
- }
- break;
+ case cesOpenFile:
+ {
+ fileOpen();
+ }
+ break;
+ case cesAutoScroll:
+ {
+ reader->setautoscroll(!reader->m_autoScroll);
+ setScrollState(reader->m_autoScroll);
+ }
+ break;
+ case cesActionMark:
+ {
+ addbkmk();
+ }
+ break;
+ case cesFullScreen:
+ {
+ m_actFullscreen->setOn(true);
+ }
+ break;
+ default:
+ {
+ qDebug("Unknown ActionType:%u", m_spaceTarget);
+ }
+ break;
}
}
void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
void QTReaderApp::restoreFocus() { reader->setFocus(); }
+
+/*
+void QTReaderApp::setstate(unsigned char* _sd, unsigned short _sdlen)
+{
+ unsigned short sdlen;
+ memcpy(&sdlen, _sd, sizeof(sdlen));
+ sdlen -= sizeof(sdlen);
+ _sd += sizeof(sdlen);
+ statedata* sd;
+ char* data;
+ if (sdlen < sizeof(statedata)+1)
+ {
+ sdlen = sizeof(statedata)+1;
+ }
+ data = new char[sdlen];
+ sd = (statedata*)data;
+ memcpy(sd, _sd, sdlen);
+ data[sdlen] = 0;
+ reader->setstate(*sd);
+ delete [] data;
+}
+
+void QTReaderApp::getstate(unsigned char*& data, unsigned short& len)
+{
+ unsigned char* olddata = data;
+ unsigned short oldlen = len;
+ len = oldlen+sizeof(unsigned short)+sizeof(statedata)+reader->m_fontname.length();
+ data = new unsigned char[len];
+ memcpy(data, olddata, oldlen);
+ delete [] olddata;
+ memcpy(data+oldlen, &len, sizeof(len));
+ statedata* sd = (statedata*)(data+oldlen+sizeof(unsigned short));
+
+ sd->bstripcr = reader->bstripcr;
+ sd->btextfmt = reader->btextfmt;
+ sd->bautofmt = reader->bautofmt;
+ sd->bstriphtml = reader->bstriphtml;
+ sd->bpeanut = reader->bpeanut;
+ sd->bdehyphen = reader->bdehyphen;
+ sd->bonespace = reader->bonespace;
+ sd->bunindent = reader->bunindent;
+ sd->brepara = reader->brepara;
+ sd->bdblspce = reader->bdblspce;
+ sd->m_bpagemode = reader->m_bpagemode;
+ sd->m_navkeys = reader->m_navkeys;
+ sd->m_bMonoSpaced = reader->m_bMonoSpaced;
+ sd->bremap = reader->bremap;
+ sd->bmakebold = reader->bmakebold;
+ sd->Continuous = reader->m_continuousDocument;
+#ifdef REPALM
+ sd->brepalm = reader->brepalm;
+#endif
+ sd->bindenter = reader->bindenter;
+ sd->m_textsize = reader->m_textsize; //reader->m_fontControl.currentsize()
+ sd->m_encd = reader->m_encd;
+ sd->m_charpc = reader->m_charpc;
+ strcpy(sd->m_fontname, reader->m_fontname.latin1());
+}
+*/
diff --git a/noncore/apps/opie-reader/QTReaderApp.h b/noncore/apps/opie-reader/QTReaderApp.h
index 22c57e4..cb33e4a 100644
--- a/noncore/apps/opie-reader/QTReaderApp.h
+++ b/noncore/apps/opie-reader/QTReaderApp.h
@@ -23,7 +23,7 @@
//#define __ISEARCH
#define MAX_ENCODING 6
-#define MAX_ACTIONS 3
+#define MAX_ACTIONS 4
#include <qmainwindow.h>
#include "CExpander.h"
@@ -39,7 +39,7 @@ class QWidgetStack;
class QToolButton;
class QPopupMenu;
class QToolBar;
-class QPEToolBar;
+//class QPEToolBar;
class CBkmkSelector;
class QProgressBar;
class QAction;
@@ -47,12 +47,14 @@ class CAnnoEdit;
class QFloatBar;
class CDrawBuffer;
class QTReader;
+class QPixmap;
enum ActionTypes
{
cesOpenFile = 0,
cesAutoScroll,
- cesActionMark
+ cesActionMark,
+ cesFullScreen
};
#ifdef __ISEARCH
@@ -65,6 +67,7 @@ struct searchrecord
#endif
class infowin;
+class GraphicWin;
class QTReaderApp : public QMainWindow
{
@@ -76,16 +79,18 @@ class QTReaderApp : public QMainWindow
public:
QTReaderApp( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
~QTReaderApp();
-
+ void suspend();
void openFile( const QString & );
void setScrollState(bool _b);
protected:
void setfontHelper(const QString& lcn, int size = 0);
- QAction* m_bkmkAvail;
+ QAction* m_bkmkAvail, *m_actFullscreen;
CAnnoEdit* m_annoWin;
Bkmk* m_anno;
+// void resizeEvent(QResizeEvent* e);
+ void keyPressEvent(QKeyEvent* e);
void closeEvent( QCloseEvent *e );
void readbkmks();
void do_mono(const QString&);
@@ -97,10 +102,15 @@ class QTReaderApp : public QMainWindow
bool m_doAnnotation;
bool m_doDictionary;
bool m_doClipboard;
+ bool m_fullscreen;
public:
void saveprefs();
private slots:
+ void zoomin();
+ void zoomout();
+ void setfullscreen(bool sfs);
+ void setcontinuous(bool sfs);
void setTwoTouch(bool _b);
void restoreFocus();
void OnAnnotation(bool _b)
@@ -116,6 +126,7 @@ private slots:
m_doClipboard = _b;
}
void OnWordSelected(const QString&, size_t, const QString&);
+ void showgraphic(QPixmap&);
void addAnno(const QString&, const QString&, size_t);
void addAnno(const QString&, const QString&);
void addanno();
@@ -141,13 +152,12 @@ private slots:
// void oldFile();
void showinfo();
void setDocument(const QString&);
- void TBD();
- void TBDzoom();
void indentplus();
void indentminus();
void fileOpen();
+ void fileClose();
void editCopy();
void editFind();
@@ -166,10 +176,13 @@ private slots:
void search();
#endif
- void openFile( const DocLnk & );
void showEditTools();
void stripcr(bool);
+ void onespace(bool);
+#ifdef REPALM
+// void repalm(bool);
+#endif
void peanut(bool _b);
void remap(bool);
void embolden(bool);
@@ -181,6 +194,7 @@ private slots:
void repara(bool);
void dblspce(bool);
void pagemode(bool);
+ void navkeys(bool);
// void gotobkmk(const QString& bm);
void gotobkmk(int);
void cancelbkmk();
@@ -192,8 +206,18 @@ private slots:
void OnActionPressed();
private:
+/*
+ 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;
- void listbkmk();
+ void listbkmk(CList<Bkmk>*, const QString& _lab = QString::null);
+ QString usefilebrowser();
void do_regedit();
void colorChanged( const QColor &c );
void clear();
@@ -223,11 +247,11 @@ private slots:
QWidgetStack *editorStack;
QTReader* reader;
QComboBox* m_fontSelector;
- QPEToolBar /* *menu,*/ *editBar;
+// QPEToolBar /* *menu,*/ *editBar;
+ QToolBar /* *menu,*/ *editBar;
QFloatBar *searchBar, *regBar/*, *m_fontBar*/;
QToolBar /* *searchBar, *regBar,*/ *m_fontBar;
QLineEdit *searchEdit, *regEdit;
- DocLnk *doc;
bool searchVisible;
bool regVisible;
bool m_fontVisible, m_twoTouch;
@@ -243,7 +267,9 @@ private slots:
}
*/
CList<Bkmk>* pBkmklist;
+ CList<Bkmk>* pOpenlist;
infowin* m_infoWin;
+ GraphicWin* m_graphicwin;
QProgressBar* pbar;
bool m_fBkmksChanged;
int m_nRegAction;
@@ -260,4 +286,6 @@ const int cJump = 5;
const int cMonoSpace = 6;
const int cOverlap = 7;
const int cSetTarget = 8;
+const int cOpenFile = 9;
+
#endif
diff --git a/noncore/apps/opie-reader/StateData.h b/noncore/apps/opie-reader/StateData.h
new file mode 100644
index 0000000..0cb0f07
--- a/dev/null
+++ b/noncore/apps/opie-reader/StateData.h
@@ -0,0 +1,32 @@
+#ifndef __STATEDATA_H
+#define __STATEDATA_H
+
+struct statedata
+{
+ bool bstripcr/*:1*/;
+ bool btextfmt/*:1*/;
+ bool bautofmt/*:1*/;
+ bool bstriphtml/*:1*/;
+ bool bpeanut/*:1*/;
+ bool bdehyphen/*:1*/;
+ bool bonespace/*:1*/;
+ bool bunindent/*:1*/;
+ bool brepara/*:1*/;
+ bool bdblspce/*:1*/;
+ bool m_bpagemode/*:1*/;
+ bool m_navkeys/*:1*/;
+ bool m_bMonoSpaced/*:1*/;
+ bool bremap/*:1*/;
+ bool bmakebold/*:1*/;
+ bool Continuous/*:1*/;
+#ifdef REPALM
+ bool brepalm/*:1*/;
+#endif
+ int bindenter;
+ int m_textsize;
+ int m_encd;
+ int m_charpc;
+ char m_fontname[1];
+};
+
+#endif
diff --git a/noncore/apps/opie-reader/StyleConsts.cpp b/noncore/apps/opie-reader/StyleConsts.cpp
new file mode 100644
index 0000000..e111dbd
--- a/dev/null
+++ b/noncore/apps/opie-reader/StyleConsts.cpp
@@ -0,0 +1,99 @@
+
+#include <qpixmap.h>
+#include "StyleConsts.h"
+
+GraphicLink::~GraphicLink() { delete graphic; }
+
+pmstore::~pmstore()
+{
+// qDebug("Deleting image");
+ delete graphic;
+}
+
+CStyle::~CStyle()
+{
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ }
+}
+
+CStyle::CStyle(CStyle& rhs) : graphic(NULL)
+{
+ *this = rhs;
+}
+
+CStyle::CStyle(const CStyle& rhs) : graphic(NULL)
+{
+ *this = rhs;
+}
+
+CStyle& CStyle::operator=(const CStyle& rhs)
+{
+ if (rhs.graphic != NULL)
+ {
+ (rhs.graphic->count)++;
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ }
+ graphic = rhs.graphic;
+ }
+ else
+ {
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ graphic = NULL;
+ }
+ }
+ sty = rhs.sty;
+ return *this;
+}
+
+void CStyle::clearPicture()
+{
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ graphic = NULL;
+ }
+}
+
+void CStyle::unset()
+{
+ sty.unset();
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ graphic = NULL;
+ }
+}
+
+void CStyle::setPicture(QPixmap* _g, bool il, unsigned long tgt)
+{
+ if (graphic != NULL)
+ {
+ if (--(graphic->count) == 0)
+ {
+ delete graphic;
+ }
+ graphic = NULL;
+ }
+ if (_g != NULL) graphic = new pmstore(_g, il, tgt);
+}
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h
index b6dd861..5aacdf0 100644
--- a/noncore/apps/opie-reader/StyleConsts.h
+++ b/noncore/apps/opie-reader/StyleConsts.h
@@ -3,111 +3,175 @@
typedef unsigned short StyleType;
-class CStyle
+#include <stdlib.h>
+#include <qglobal.h>
+class QPixmap;
+
+struct GraphicLink
{
-// 15 14 13-5 4 3 2 1 0
-//bold italic spare align align fs fs fs
- static const StyleType m_Bold = 1 << 15;
- static const StyleType m_Italic = 1 << 14;
- static const StyleType m_FontMask = 7;
- static const StyleType m_FontBase = 3;
-
- static const StyleType m_AlignShift = 3;
- static const StyleType m_AlignMask = 3 << m_AlignShift;
- static const StyleType m_EveryBit = 0xffff;
+ QPixmap* graphic;
+ bool isLink;
+ unsigned long link;
+ GraphicLink(QPixmap* p, bool isLnk, unsigned long tgt) :
+ graphic(p), isLink(isLnk), link(tgt) {}
+ ~GraphicLink();
+};
+struct pmstore
+{
+ unsigned int count;
+ GraphicLink* graphic;
+ pmstore(QPixmap* p, bool isLnk, unsigned long tgt) : count(1)
+ {
+ graphic = new GraphicLink(p, isLnk, tgt);
+ }
+ ~pmstore();
+};
- StyleType sty;
+enum EalignmentType
+{
+ m_AlignLeft,
+ m_AlignRight,
+ m_AlignCentre,
+ m_AlignJustify
+};
- void unjustify() { sty &= m_EveryBit ^ m_AlignMask; }
+class CBasicStyle
+{
+ friend class CStyle;
+ bool m_bold,
+ m_italic;
+ int m_fontsize;
+ EalignmentType m_align;
unsigned char red, green, blue;
unsigned long data;
bool isLink;
- public:
- unsigned char Red() { return red; }
- unsigned char Green() { return green; }
- unsigned char Blue() { return blue; }
- void setColour(unsigned char r, unsigned char g, unsigned char b)
+ bool m_underline;
+ bool m_strikethru;
+ bool m_monospaced;
+ unsigned char m_leftmargin, m_rightmargin;
+ CBasicStyle()
{
- red = r;
- green = g;
- blue = b;
- }
- static const StyleType m_AlignLeft = 0;
- static const StyleType m_AlignRight = 1 << m_AlignShift;
- static const StyleType m_AlignCentre = 2 << m_AlignShift;
- static const StyleType m_AlignJustify = 3 << m_AlignShift;
- CStyle()
- :
- sty(m_FontBase),
- red(0), green(0), blue(0),
- data(0), isLink(false)
- {}
-// CStyle(const int _fs) : sty(m_FontBase+_fs) {}
-
+ unset();
+ }
+ bool operator!=(const CBasicStyle& rhs)
+ {
+ return (memcmp(this, &rhs, sizeof(CBasicStyle)) != 0);
+ }
void unset()
{
- sty = m_FontBase;
+ m_bold = false;
+ m_italic = false;
+ m_fontsize = 0;
+ m_align = m_AlignLeft;
red = green = blue = 0;
data = 0;
isLink = false;
+ m_underline = false;
+ m_strikethru = false;
+ m_leftmargin = 0;
+ m_rightmargin = 0;
+ m_monospaced = false;
}
+};
- void setBold() { sty |= m_Bold; }
- void setItalic() { sty |= m_Italic; }
- void unsetBold() { sty &= m_EveryBit ^ m_Bold; }
- void unsetItalic() { sty &= m_EveryBit ^ m_Italic; }
- bool isBold() { return ((sty & m_Bold) != 0); }
- bool isItalic() { return ((sty & m_Italic) != 0); }
+class CStyle
+{
+ CBasicStyle sty;
+ pmstore* graphic;
+ public:
+ bool getPictureLink()
+ {
+ return (graphic != NULL && graphic->graphic->isLink);
+ }
+ unsigned long getPictureLinkData()
+ {
+ return graphic->graphic->link;
+ }
+ void setLeftMargin(unsigned char m) { sty.m_leftmargin = m; }
+ unsigned char getLeftMargin() { return sty.m_leftmargin; }
+ void setRightMargin(unsigned char m) { sty.m_rightmargin = m; }
+ unsigned char getRightMargin() { return sty.m_rightmargin; }
+ unsigned char Red() { return sty.red; }
+ unsigned char Green() { return sty.green; }
+ unsigned char Blue() { return sty.blue; }
+ void setColour(unsigned char r, unsigned char g, unsigned char b)
+ {
+ sty.red = r;
+ sty.green = g;
+ sty.blue = b;
+ }
+ CStyle() : graphic(NULL) {}
+ ~CStyle();
+ CStyle(CStyle&);
+ CStyle(const CStyle&);
+ CStyle& operator=(const CStyle&);
+ void unset();
+ bool isPicture() { return (graphic != NULL); }
+ void clearPicture();
+ void setPicture(QPixmap* _g, bool il=false, unsigned long tgt=0);
+ QPixmap* getPicture()
+ {
+ QPixmap* pm = ((graphic != NULL) ? graphic->graphic->graphic : NULL);
+ return pm;
+ }
+ void setUnderline() { sty.m_underline = true; }
+ void unsetUnderline() { sty.m_underline = false; }
+ bool isUnderline() { return sty.m_underline; }
+ void setStrikethru() { sty.m_strikethru = true; }
+ void unsetStrikethru() { sty.m_strikethru = false; }
+ bool isStrikethru() { return sty.m_strikethru; }
+ void setBold() { sty.m_bold = true; }
+ void unsetBold() { sty.m_bold = false; }
+ bool isBold() { return sty.m_bold; }
+ void setItalic() { sty.m_italic = true; }
+ void unsetItalic() { sty.m_italic = false; }
+ bool isItalic() { return sty.m_italic; }
+ void setMono() { sty.m_monospaced = true; }
+ void unsetMono() { sty.m_monospaced = false; }
+ bool isMono() { return sty.m_monospaced; }
void setLeftJustify()
{
- unjustify();
- sty |= m_AlignLeft;
+ sty.m_align = m_AlignLeft;
}
void setRightJustify()
{
- unjustify();
- sty |= m_AlignRight;
+ sty.m_align = m_AlignRight;
}
void setCentreJustify()
{
- unjustify();
- sty |= m_AlignCentre;
+ sty.m_align = m_AlignCentre;
}
void setFullJustify()
{
- unjustify();
- sty |= m_AlignJustify;
+ sty.m_align = m_AlignJustify;
}
StyleType getJustify()
{
- return sty & m_AlignMask;
+ return sty.m_align;
}
void setFontSize(int _fs)
{
- sty &= m_EveryBit ^ m_FontMask;
- sty |= m_FontBase + _fs;
+ sty.m_fontsize = _fs;
}
int getFontSize()
{
- return (sty & m_FontMask) - m_FontBase;
+ return sty.m_fontsize;
}
bool operator!=(const CStyle& rhs)
{
return
- (
- (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) ||
- (blue != rhs.blue) ||
- (data != rhs.data) ||
- (isLink != rhs.isLink)
- );
- }
- void setLink(bool _l) { isLink = _l; }
- bool getLink() { return isLink; }
- void setData(unsigned long _d) { data = _d; }
- unsigned long getData() { return data; }
+ (
+ (sty != rhs.sty) ||
+ (graphic != rhs.graphic)
+ );
+ }
+ void setLink(bool _l) { sty.isLink = _l; }
+ bool getLink() { return sty.isLink; }
+ void setData(unsigned long _d) { sty.data = _d; }
+ unsigned long getData() { return sty.data; }
};
#endif
diff --git a/noncore/apps/opie-reader/Text.h b/noncore/apps/opie-reader/Text.h
deleted file mode 100644
index 4c689be..0000000
--- a/noncore/apps/opie-reader/Text.h
+++ b/dev/null
@@ -1,28 +0,0 @@
-#ifndef __Text_h
-#define __Text_h
-#include <stdio.h>
-#include <sys/stat.h>
-#include "CExpander.h"
-
-class Text: public CExpander {
- FILE* file;
-public:
- Text() : file(NULL) {};
- virtual ~Text() { if (file != NULL) fclose(file); }
- virtual int openfile(const tchar *src)
- {
- if (file != NULL) fclose(file);
- return ((file = fopen(src,"rb")) == NULL);
- }
- virtual int getch() { return fgetc(file); }
- virtual unsigned int locate() { return ftell(file); }
- virtual void locate(unsigned int n) { fseek(file,n,SEEK_SET); }
- virtual bool hasrandomaccess() { return true; }
- virtual void sizes(unsigned long& _file, unsigned long& _text)
- {
- struct stat _stat;
- fstat(fileno(file),&_stat);
- _text = _file = _stat.st_size;
- }
-};
-#endif
diff --git a/noncore/apps/opie-reader/ZText.h b/noncore/apps/opie-reader/ZText.h
index debfe8c..22d3733 100644
--- a/noncore/apps/opie-reader/ZText.h
+++ b/noncore/apps/opie-reader/ZText.h
@@ -10,14 +10,43 @@ class Text: public CExpander {
gzFile file;
unsigned long fsize;
public:
+ virtual void suspend()
+ {
+ bSuspended = true;
+ suspos = gztell(file);
+ gzclose(file);
+ file = NULL;
+ sustime = time(NULL);
+ }
+ virtual void unsuspend()
+ {
+ if (bSuspended)
+ {
+ bSuspended = false;
+ 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);
+ }
+ }
Text() : file(NULL) {};
virtual ~Text()
{
if (file != NULL) gzclose(file);
}
- virtual int openfile(const char *src)
+ virtual int OpenFile(const char *src)
{
- if (file != NULL) gzclose(file);
+ if (file != NULL) gzclose(file);
struct stat _stat;
stat(src,&_stat);
fsize = _stat.st_size;
@@ -33,7 +62,7 @@ public:
}
virtual MarkupType PreferredMarkup()
{
- return cTEXT;
+ return cTEXT;
}
};
#endif
diff --git a/noncore/apps/opie-reader/cbkmkselector.h b/noncore/apps/opie-reader/cbkmkselector.h
index 1a49c5a..1a70048 100644
--- a/noncore/apps/opie-reader/cbkmkselector.h
+++ b/noncore/apps/opie-reader/cbkmkselector.h
@@ -9,6 +9,7 @@ class CBkmkSelector : public QWidget
Q_OBJECT
QListBox* bkmkselector;
+ QPushButton* exitButton;
signals:
void selected(int i);
@@ -27,7 +28,7 @@ public:
QVBoxLayout* grid = new QVBoxLayout(this);
bkmkselector = new QListBox(this, "Bookmarks");
- QPushButton* exitButton = new QPushButton("Cancel", this);
+ exitButton = new QPushButton("Cancel", this);
connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( slotSelected(int) ) );
connect(bkmkselector, SIGNAL( clicked(QListBoxItem*) ), this, SLOT( slotSelected(QListBoxItem*) ) );
connect(exitButton, SIGNAL( released() ), this, SLOT( slotCancel() ) );
@@ -37,5 +38,6 @@ public:
void clear() { bkmkselector->clear(); }
void insertItem(const QString& item) { bkmkselector->insertItem(item); }
QString text(int index) const { return bkmkselector->text(index); }
+ void setText(const QString& _l) { exitButton->setText(_l); }
};
diff --git a/noncore/apps/opie-reader/config.h b/noncore/apps/opie-reader/config.h
index 5150270..b6281a4 100644
--- a/noncore/apps/opie-reader/config.h
+++ b/noncore/apps/opie-reader/config.h
@@ -18,4 +18,8 @@ const int UEOF = -1;
#include "ustring.h"
+#define BORDER 2
+
+//#define _FAST
+
#endif
diff --git a/noncore/apps/opie-reader/fileBrowser.cpp b/noncore/apps/opie-reader/fileBrowser.cpp
index b21d59d..21c970b 100644
--- a/noncore/apps/opie-reader/fileBrowser.cpp
+++ b/noncore/apps/opie-reader/fileBrowser.cpp
@@ -39,6 +39,7 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
buttonShowHidden->setOn( false );
dirLabel = new QLabel(this, "DirLabel");
+ dirLabel->setAlignment(AlignLeft | AlignVCenter | ExpandTabs | WordBreak);
dirLabel->setText(currentDir.canonicalPath());
ListView = new QtrListView( this, "ListView" );
@@ -47,6 +48,8 @@ fileBrowser::fileBrowser( QWidget* parent, const char* name, bool modal, WFlags
ListView->addColumn( tr( "Size" ) );
ListView->setSelectionMode(QListView::Single);
ListView->setAllColumnsShowFocus( TRUE );
+ ListView->setColumnWidthMode(0, QListView::Manual);
+ ListView->setColumnWidthMode(1, QListView::Manual);
// signals and slots connections
connect( buttonShowHidden, SIGNAL( toggled(bool) ), this, SLOT( setHidden(bool) ) );
diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp
index 7b8f280..30adebf 100644
--- a/noncore/apps/opie-reader/infowin.cpp
+++ b/noncore/apps/opie-reader/infowin.cpp
@@ -1,8 +1,9 @@
+#include "name.h"
#include "infowin.h"
#include "version.h"
#include <stdio.h>
-infowin::infowin( QWidget *parent, const char *name, WFlags f) :
+infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
QWidget(parent, name, f)
{
grid = new QGridLayout(this, 6, 2);
@@ -33,7 +34,7 @@ infowin::infowin( QWidget *parent, const char *name, WFlags f) :
read->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(read, 4, 1);
char vstr[128];
- sprintf(vstr, "QT Reader v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
+ sprintf(vstr, PROGNAME " v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
l = new QLabel(vstr, this);
grid->addWidget(l, 5, 0);
QPushButton* exitbutton = new QPushButton("Cancel", this);
diff --git a/noncore/apps/opie-reader/main.cpp b/noncore/apps/opie-reader/main.cpp
index 08f59a8..2440037 100644
--- a/noncore/apps/opie-reader/main.cpp
+++ b/noncore/apps/opie-reader/main.cpp
@@ -9,7 +9,11 @@ QTReaderApp* app = NULL;
void handler(int signum)
{
- if (app != NULL) app->saveprefs();
+ if (app != NULL)
+ {
+ app->suspend();
+ app->saveprefs();
+ }
signal(signum, handler);
}
diff --git a/noncore/apps/opie-reader/name.h b/noncore/apps/opie-reader/name.h
new file mode 100644
index 0000000..d419005
--- a/dev/null
+++ b/noncore/apps/opie-reader/name.h
@@ -0,0 +1,8 @@
+#ifndef __NAME_H
+#define __NAME_H
+
+#define PROGNAME "Opie-Reader"
+#define SHORTPROGNAME "Reader"
+#define APPDIR "uqtreader"
+
+#endif
diff --git a/noncore/apps/opie-reader/opie-reader.pro b/noncore/apps/opie-reader/opie-reader.pro
index 51849a3..139c03a 100644
--- a/noncore/apps/opie-reader/opie-reader.pro
+++ b/noncore/apps/opie-reader/opie-reader.pro
@@ -1,58 +1,73 @@
-TEMPLATE = app
-CONFIG = qt warn_on release
-HEADERS = Aportis.h \
- BuffDoc.h \
- CBuffer.h \
- CDrawBuffer.h \
- CExpander.h \
- CFilter.h \
- QTReader.h \
- QTReaderApp.h \
- ZText.h \
- arith.h \
- my_list.h \
- ppm.h \
- ppm_expander.h \
- cbkmkselector.h \
- fileBrowser.h \
- ztxt.h \
- QtrListView.h \
- infowin.h \
- version.h \
- pdb.h \
- utypes.h \
- ustring.h \
- CEncoding.h \
- CAnnoEdit.h \
- QFloatBar.h \
- StyleConsts.h \
- FontControl.h \
- plucker.h \
- Markups.h \
- Bkmks.h \
- config.h
-SOURCES = Aportis.cpp \
- BuffDoc.cpp \
- CBuffer.cpp \
- CDrawBuffer.cpp \
- QTReader.cpp \
- QTReaderApp.cpp \
- arith_d.cpp \
- main.cpp \
- ppm.cpp \
- ppm_expander.cpp \
- ztxt.cpp \
- QtrListView.cpp \
- infowin.cpp \
- pdb.cpp \
- CEncoding.cpp \
- CFilter.cpp \
- plucker.cpp \
- Bkmks.cpp \
- fileBrowser.cpp
-DESTDIR = $(OPIEDIR)/bin
-INCLUDEPATH += $(OPIEDIR)/include
-DEPENDPATH += $(OPIEDIR)/include
-TARGET = reader
-LIBS += -lqpe
+TEMPLATE = app
+CONFIG = qt warn_on release
+HEADERS = Aportis.h \
+ Bkmks.h \
+ BuffDoc.h \
+ CAnnoEdit.h \
+ CBuffer.h \
+ CDrawBuffer.h \
+ CEncoding.h \
+ CExpander.h \
+ CFilter.h \
+ Filedata.h \
+ FontControl.h \
+ GraphicWin.h \
+ Markups.h \
+ Navigation.h \
+ Palm2QImage.h \
+ QFloatBar.h \
+ QTReader.h \
+ QTReaderApp.h \
+ QtrListView.h \
+ Queue.h \
+ StateData.h \
+ StyleConsts.h \
+ ZText.h \
+ arith.h \
+ cbkmkselector.h \
+ config.h \
+ fileBrowser.h \
+ infowin.h \
+ my_list.h \
+ name.h \
+ opie.h \
+ pdb.h \
+ plucker.h \
+ ppm.h \
+ ppm_expander.h \
+ ustring.h \
+ utypes.h \
+ version.h \
+ ztxt.h
+
+SOURCES = Aportis.cpp \
+ Bkmks.cpp \
+ BuffDoc.cpp \
+ CBuffer.cpp \
+ CDrawBuffer.cpp \
+ CEncoding.cpp \
+ CFilter.cpp \
+ FontControl.cpp \
+ Navigation.cpp \
+ Palm2QImage.cpp \
+ QTReader.cpp \
+ QTReaderApp.cpp \
+ QtrListView.cpp \
+ StyleConsts.cpp \
+ arith_d.cpp \
+ fileBrowser.cpp \
+ infowin.cpp \
+ main.cpp \
+ pdb.cpp \
+ plucker.cpp \
+ ppm.cpp \
+ ppm_expander.cpp \
+ ztxt.cpp
+
+INTERFACES =
+DESTDIR = $(OPIEDIR)/bin
+INCLUDEPATH += $(OPIEDIR)/include
+DEPENDPATH += $(OPIEDIR)/include
+TARGET = reader
+LIBS += -lqpe
diff --git a/noncore/apps/opie-reader/opie.h b/noncore/apps/opie-reader/opie.h
new file mode 100644
index 0000000..e28c2ab
--- a/dev/null
+++ b/noncore/apps/opie-reader/opie.h
@@ -0,0 +1,6 @@
+#ifndef __OPIE_H
+#define __OPIE_H
+
+#define OPIE
+
+#endif
diff --git a/noncore/apps/opie-reader/pdb.cpp b/noncore/apps/opie-reader/pdb.cpp
index 68b904e..3054424 100644
--- a/noncore/apps/opie-reader/pdb.cpp
+++ b/noncore/apps/opie-reader/pdb.cpp
@@ -1,4 +1,7 @@
#include "pdb.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
size_t Cpdb::recordpos(int n)
{
@@ -46,10 +49,13 @@ bool Cpdb::openfile(const char *src)
// just holds the first few chars of the file
// char buf[0x100];
- fseek(fin,0,SEEK_END);
- file_length = ftell(fin);
+ struct stat buf;
+ stat(src, &buf);
+ file_length = buf.st_size;
+// fseek(fin,0,SEEK_END);
+// file_length = ftell(fin);
- fseek(fin,0,SEEK_SET);
+// fseek(fin,0,SEEK_SET);
fread(&head, 1, sizeof(head), fin);
diff --git a/noncore/apps/opie-reader/plucker.cpp b/noncore/apps/opie-reader/plucker.cpp
index ddda4bc..eb039de 100644
--- a/noncore/apps/opie-reader/plucker.cpp
+++ b/noncore/apps/opie-reader/plucker.cpp
@@ -1,18 +1,58 @@
#include <stdio.h>
#include <string.h>
#include <qmessagebox.h>
-#include "plucker.h"
+#include <qpixmap.h>
+#include <qpe/qcopenvelope_qws.h>
+#ifdef LOCALPICTURES
+#include <qscrollview.h>
+#endif
+#include <qpe/global.h>
+#include <qclipboard.h>
+#include <qpe/qpeapplication.h>
+#include "plucker.h"
#include "Aportis.h"
+#include "Palm2QImage.h"
+#include "name.h"
+
+CPlucker::CPlucker() :
+#ifdef LOCALPICTURES
+ m_viewer(NULL),
+ m_picture(NULL),
+#endif
+ expandedtextbuffer(NULL),
+ compressedtextbuffer(NULL),
+ urls(NULL)
+ { /*printf("constructing:%x\n",fin);*/ }
-CPlucker::CPlucker() : expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
+void CPlucker::Expand(UInt16 reclen, UInt8 type, UInt8* buffer, UInt16 buffersize)
+{
+ if (type%2 == 0)
+ {
+ fread(buffer, reclen, sizeof(char), fin);
+ }
+ else
+ {
+ fread(compressedtextbuffer, reclen, sizeof(char), fin);
+ switch (ntohs(hdr0.version))
+ {
+ case 2:
+ UnZip(reclen, buffer, buffersize);
+ break;
+ case 1:
+ UnDoc(reclen, buffer, buffersize);
+ break;
+ }
+ }
+}
-int CPlucker::openfile(const char *src)
+int CPlucker::OpenFile(const char *src)
{
+ m_lastBreak = 0;
if (!Cpdb::openfile(src))
{
- return -1;
+ return -1;
}
//printf("Okay %u\n", 4);
@@ -21,15 +61,7 @@ int CPlucker::openfile(const char *src)
// qDebug("Cool - this IS plucker");
- textlength = 0;
- for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
- {
- CPlucker_dataRecord thisHdr;
- gotorecordnumber(recptr);
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
- if (thisHdr.type < 2) textlength += htons(thisHdr.size);
- }
-
+ EOPPhase = 0;
gotorecordnumber(0);
fread(&hdr0, 1, sizeof(hdr0), fin);
//printf("Okay %u\n", 5);
@@ -37,18 +69,144 @@ int CPlucker::openfile(const char *src)
compressedtextbuffer = new UInt8[buffersize];
expandedtextbuffer = new UInt8[buffersize];
-// qDebug("Total number of records:%u", ntohs(head.recordList.numRecords));
+ qDebug("Total number of records:%u", ntohs(head.recordList.numRecords));
unsigned int nrecs = ntohs(hdr0.nRecords);
-// qDebug("Version %u, no. res %u", ntohs(hdr0.version), nrecs);
- for (unsigned int i = 0; i < 4*nrecs; i++)
+ qDebug("Version %u, no. recs %u", ntohs(hdr0.version), nrecs);
+ UInt16 homerecid = 1;
+ UInt16 urlid = 0;
+ bool urlsfound = false;
+ for (unsigned int i = 0; i < nrecs; i++)
{
- UInt8 id;
- fread(&id, 1, sizeof(id), fin);
-// qDebug("%x", id);
+ 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) == 0) homerecid = ntohs(id);
+ if (ntohs(name) == 2)
+ {
+ urlsfound = true;
+ urlid = id;
+ qDebug("Found url index:%d", ntohs(urlid));
+ }
+// qDebug("%x", id);
}
+
+ textlength = 0;
+ for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
+ {
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (ntohs(thisHdr.uid) == homerecid)
+ {
+ m_homepos = textlength;
+ qDebug("Home pos found after %u records", recptr);
+ break;
+ }
+ if (thisHdr.type < 2) textlength += ntohs(thisHdr.size);
+ }
+ textlength = 0;
+
+ if (urlsfound)
+ {
+ unsigned short recptr = finduid(ntohs(urlid));
+ if (recptr != 0)
+ {
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ fread(&urlid, 1, sizeof(urlid), fin);
+ fread(&urlid, 1, sizeof(urlid), fin);
+ qDebug("urls are in %d", ntohs(urlid));
+ recptr = finduid(ntohs(urlid));
+ if (recptr != 0)
+ {
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ qDebug("Found urls:%x",thisHdr.type);
+ UInt16 reclen = recordlength(recptr) - sizeof(thisHdr);
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ urlsize = ntohs(thisHdr.size);
+ urls = new char[urlsize];
+ Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize);
+ }
+ }
+ }
+/*
+ for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
+ {
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.uid == urlid)
+ {
+ qDebug("Found urls:%x",thisHdr.type);
+ UInt16 reclen = recordlength(recptr) - sizeof(thisHdr);
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ urlsize = ntohs(thisHdr.size);
+ urls = new char[urlsize];
+ Expand(reclen, thisHdr.type, (UInt8*)urls, urlsize);
+ break;
+ }
+ }
+*/
home();
+#ifdef LOCALPICTURES
+ if (m_viewer == NULL)
+ {
+ m_viewer = new QScrollView(NULL);
+ m_picture = new QWidget(m_viewer->viewport());
+ m_viewer->addChild(m_picture);
+ }
+#endif
return 0;
+
+}
+
+void CPlucker::sizes(unsigned long& _file, unsigned long& _text)
+{
+ qDebug("Sizes called:%u",textlength);
+ _file = file_length;
+ if (textlength == 0)
+ {
+ for (int recptr = 1; recptr < ntohs(head.recordList.numRecords); recptr++)
+ {
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(recptr);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.type < 2) textlength += ntohs(thisHdr.size);
+ }
+ }
+ _text = textlength;
+//ntohl(hdr0.size);
+}
+
+
+char* CPlucker::geturl(UInt16 i)
+{
+ if (urls == NULL) return NULL;
+ char* ptr = urls;
+ int rn = 1;
+ while (ptr - urls < urlsize)
+ {
+ if (rn == i) return ptr;
+ ptr += strlen(ptr)+1;
+ rn++;
+ }
+ return NULL;
+}
+
+CPlucker::~CPlucker()
+{
+ if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
+ if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
+ if (urls != NULL) delete [] urls;
+#ifdef LOCALPICTURES
+ if (m_viewer != NULL) delete m_viewer;
+#endif
}
int CPlucker::bgetch()
@@ -56,207 +214,355 @@ int CPlucker::bgetch()
int ch = EOF;
if (bufferpos >= buffercontent)
{
- if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF;
-// qDebug("Passing through %u", currentpos);
- if (!expand(bufferrec+1)) return EOF;
- mystyle.unset();
+ if (!m_continuous) return EOF;
+ if (bufferrec >= ntohs(head.recordList.numRecords) - 1) return EOF;
+// qDebug("Passing through %u", currentpos);
+ if (!expand(bufferrec+1)) return EOF;
+ mystyle.unset();
+ ch = 10;
+ EOPPhase = 4;
}
-
- if (bufferpos == m_nextPara)
+ else if (bufferpos == m_nextPara)
{
- UInt16 attr = m_ParaAttrs[m_nextParaIndex];
- m_nextParaIndex++;
- if (m_nextParaIndex == m_nParas)
- {
- m_nextPara = -1;
- }
- else
- {
- m_nextPara += m_ParaOffsets[m_nextParaIndex];
- }
-// qDebug("New paragraph");
- ch = 10;
+ while (bufferpos == m_nextPara)
+ {
+ UInt16 attr = m_ParaAttrs[m_nextParaIndex];
+ m_nextParaIndex++;
+ if (m_nextParaIndex == m_nParas)
+ {
+ m_nextPara = -1;
+ }
+ else
+ {
+ m_nextPara += m_ParaOffsets[m_nextParaIndex];
+ }
+ }
+ mystyle.unset();
+ if (m_lastBreak == locate())
+ {
+ currentpos++;
+ ch = expandedtextbuffer[bufferpos++];
+ }
+ else
+ {
+ ch = 10;
+ }
}
else
{
- currentpos++;
- ch = expandedtextbuffer[bufferpos++];
+ currentpos++;
+ ch = expandedtextbuffer[bufferpos++];
}
return ch;
}
int CPlucker::getch()
{
- int ch = bgetch();
- while (ch == 0)
- {
- ch = bgetch();
-// qDebug("Function:%x", ch);
- switch (ch)
- {
- case 0x38:
- ch = 10;
- break;
- case 0x0a:
- case 0x0c:
- {
- unsigned long ln = 0;
- int skip = ch & 7;
- for (int i = 0; i < 2; i++)
+ mystyle.clearPicture();
+
+
+ if (EOPPhase > 0)
{
- int ch = bgetch();
- ln = (ln << 8) + ch;
-// qDebug("ch:%d, ln:%u", ch, ln);
+ int ch = 10;
+ switch (EOPPhase)
+ {
+ case 4:
+ mystyle.setPicture(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;
}
- if (skip == 2)
+
+
+ int ch = bgetch();
+ while (ch == 0)
{
- ln <<= 16;
+ 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();
+ }
+ 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);
+ switch (ch)
+ {
+ case 0:
+ mystyle.unsetMono();
+ mystyle.unsetBold();
+ mystyle.setFontSize(0);
+ break;
+ case 1:
+ mystyle.unsetMono();
+ mystyle.setBold();
+ mystyle.setFontSize(3);
+ break;
+ case 2:
+ mystyle.unsetMono();
+ mystyle.setBold();
+ mystyle.setFontSize(2);
+ break;
+ case 3:
+ mystyle.unsetMono();
+ mystyle.setBold();
+// mystyle.unsetBold();
+ mystyle.setFontSize(1);
+ break;
+ case 4:
+ mystyle.unsetMono();
+ mystyle.setBold();
+// mystyle.unsetBold();
+ mystyle.setFontSize(0);
+ break;
+ case 5:
+ mystyle.unsetMono();
+ mystyle.setBold();
+ mystyle.setFontSize(0);
+ break;
+ case 6:
+ mystyle.unsetMono();
+ mystyle.setBold();
+ mystyle.setFontSize(0);
+ break;
+ case 7:
+ mystyle.unsetMono();
+ mystyle.setBold();
+ mystyle.setFontSize(0);
+ break;
+ case 8: // should be fixed width
+ qDebug("Trying fixed width");
+ mystyle.unsetBold();
+ mystyle.setFontSize(0);
+ mystyle.setMono();
+ break;
+ default:
+ mystyle.unsetBold();
+ mystyle.unsetMono();
+ mystyle.setFontSize(0);
+ 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();
+ mystyle.setPicture(expandimg(ir2, true), true, ir);
+#ifdef LOCALPICTURES
+ UInt32 ln = ir;
+ ln <<= 16;
+ mystyle.setLink(true);
+ mystyle.setData(ln);
+#endif
+ }
+ else
+ {
+ mystyle.setPicture(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 = (240*(unsigned long)pc)/100;
+ }
+ if (w == 0) w = 320;
+ mystyle.setPicture(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:
+ 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();
+ }
+ }
}
- else
+
+ if (m_lastIsBreak && !mystyle.isMono())
{
- 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);
- ch = bgetch();
- }
- break;
- case 0x08:
- ch = bgetch();
- mystyle.setColour(0, 0, 0);
- 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);
- switch (ch)
- {
- case 0:
- mystyle.unsetBold();
- mystyle.setFontSize(0);
- break;
- case 1:
- mystyle.setBold();
- mystyle.setFontSize(1);
- break;
- case 2:
- mystyle.setBold();
- mystyle.setFontSize(1);
- break;
- case 3:
-// mystyle.setBold();
- mystyle.setFontSize(1);
- break;
- case 4:
-// mystyle.setBold();
- mystyle.setFontSize(1);
- break;
- case 5:
- mystyle.setBold();
- mystyle.setFontSize(0);
- break;
- case 6:
- mystyle.setBold();
- mystyle.setFontSize(0);
- break;
- case 7:
- mystyle.setBold();
- mystyle.setFontSize(0);
- break;
- case 8: // should be fixed width
- mystyle.unsetBold();
- mystyle.setFontSize(0);
- break;
- default:
- mystyle.unsetBold();
- mystyle.setFontSize(0);
- 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:
-/*
- {
- UInt16 ir = bgetch();
- ir = (ir << 8) + bgetch();
- expandimg(ir);
- }
- ch = bgetch();
- break;
-*/
- case 0x33:
- case 0x22:
- case 0x5c:
- case 0x60:
- case 0x68:
- case 0x70:
- case 0x78:
- case 0x83:
- 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();
- }
- }
+ while (ch == ' ')
+ {
+ ch = getch();
+ }
}
+
+ m_lastIsBreak = (ch == 10);
+
return ch;
}
@@ -276,10 +582,10 @@ unsigned int CPlucker::locate()
CPlucker_dataRecord thisHdr;
while (thisrec < bufferrec)
{
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
- if (thisHdr.type < 2) locpos += htons(thisHdr.size);
- thisrec++;
- gotorecordnumber(thisrec);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.type < 2) locpos += ntohs(thisHdr.size);
+ thisrec++;
+ gotorecordnumber(thisrec);
}
return locpos+bufferpos;
*/
@@ -293,57 +599,255 @@ void CPlucker::locate(unsigned int n)
CPlucker_dataRecord thisHdr;
do
{
- thisrec++;
- locpos += bs;
- gotorecordnumber(thisrec);
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
- if (thisHdr.type < 2)
- {
- bs = htons(thisHdr.size);
- }
- else
- {
- bs = 0;
- }
- } while (locpos + bs < n);
+ thisrec++;
+ locpos += bs;
+ gotorecordnumber(thisrec);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.type < 2)
+ {
+ bs = ntohs(thisHdr.size);
+ }
+ else
+ {
+ bs = 0;
+ }
+ } while (locpos + bs <= n);
currentpos = locpos;
expand(thisrec);
+#ifdef _FAST
while (currentpos < n && bufferpos < buffercontent) bgetch();
+#else
+ while (currentpos < n && bufferpos < buffercontent) getch();
+#endif
}
bool CPlucker::hyperlink(unsigned int n)
{
+ visited.push_front(n);
UInt16 tuid = (n >> 16);
n &= 0xffff;
+// qDebug("Hyper:<%u,%u>", tuid, n);
UInt16 thisrec = 1;
currentpos = 0;
gotorecordnumber(thisrec);
CPlucker_dataRecord thisHdr;
while (1)
{
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
- if (tuid <= htons(thisHdr.uid)) break;
- if (thisHdr.type < 2) currentpos += htons(thisHdr.size);
-// qDebug("hyper-cp:%u", currentpos);
- thisrec++;
- gotorecordnumber(thisrec);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (tuid == ntohs(thisHdr.uid)) break;
+ if (thisHdr.type < 2) currentpos += ntohs(thisHdr.size);
+// qDebug("hyper-cp:%u", currentpos);
+ thisrec++;
+ if (thisrec >= ntohs(head.recordList.numRecords))
+ {
+ if (urls == NULL)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("No external links\nin this pluck")
+ );
+ }
+ else
+ {
+ char *turl = geturl(tuid);
+ if (turl == NULL)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Couldn't find link")
+ );
+ }
+ else
+ {
+ QString wrd(turl);
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(wrd);
+ if (wrd.length() > 10)
+ {
+ Global::statusMessage(wrd.left(8) + "..");
+ }
+ }
+ }
+ return false;
+ }
+ gotorecordnumber(thisrec);
}
if (thisHdr.type > 1)
{
- QMessageBox::information(NULL,
- QString("OpieReader"),
- QString("External links\nnot yet supported")
- );
- return false;
+ if (thisHdr.type == 4)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Mailto links\nnot yet supported (2)"));
+ }
+ else
+ {
+#ifdef LOCALPICTURES
+ if (thisHdr.type > 3)
+ {
+#endif
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("External links\nnot yet supported (2)")
+ );
+#ifdef LOCALPICTURES
+ }
+ else
+ {
+ showimg(tuid);
+ }
+#endif
+ }
+ return false;
+ }
+/*
+ if (thisHdr.type == 2 || thisHdr.type == 3)
+ {
+ expandimg(thisrec);
+
}
+*/
else
{
- expand(thisrec);
- while (bufferpos < n && bufferpos < buffercontent) getch();
+ expand(thisrec);
+ if (n != 0)
+ {
+ if (n >= m_nParas)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Error in link\nPara # too big")
+ );
+ return false;
+ }
+ unsigned int noff = 0;
+ for (int i = 0; i < n; i++) noff += m_ParaOffsets[i];
+ n = noff;
+ }
+ if (n > ntohs(thisHdr.size))
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Error in link\nOffset too big")
+ );
+ return false;
+ }
+ qDebug("Hyper:<%u,%u>", tuid, n);
+ while (bufferpos < n && bufferpos < buffercontent) getch();
}
return true;
}
+/*
+bool CPlucker::hyperlink(unsigned int n)
+{
+ visited.push_front(n);
+ UInt16 tuid = (n >> 16);
+ n &= 0xffff;
+// qDebug("Hyper:<%u,%u>", tuid, n);
+ UInt16 thisrec = finduid(tuid);
+ if (thisrec == 0)
+ {
+ if (urls == NULL)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("No external links\nin this pluck")
+ );
+ }
+ else
+ {
+ char *turl = geturl(tuid);
+ if (turl == NULL)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Couldn't find link")
+ );
+ }
+ else
+ {
+ QString wrd(turl);
+ QClipboard* cb = QApplication::clipboard();
+ cb->setText(wrd);
+ if (wrd.length() > 10)
+ {
+ Global::statusMessage(wrd.left(8) + "..");
+ }
+ }
+ }
+ return false;
+ }
+ else
+ {
+ currentpos = 0;
+ gotorecordnumber(thisrec);
+ CPlucker_dataRecord thisHdr;
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.type > 1)
+ {
+ if (thisHdr.type == 4)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Mailto links\nnot yet supported (2)"));
+ }
+ else
+ {
+#ifdef LOCALPICTURES
+ if (thisHdr.type > 3)
+ {
+#endif
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("External links\nnot yet supported (2)")
+ );
+#ifdef LOCALPICTURES
+ }
+ else
+ {
+ showimg(tuid);
+ }
+#endif
+ }
+ return false;
+ }
+// if (thisHdr.type == 2 || thisHdr.type == 3)
+// {
+// expandimg(thisrec);
+// }
+ else
+ {
+ expand(thisrec);
+ if (n != 0)
+ {
+ if (n >= m_nParas)
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Error in link\nPara # too big")
+ );
+ return false;
+ }
+ unsigned int noff = 0;
+ for (int i = 0; i < n; i++) noff += m_ParaOffsets[i];
+ n = noff;
+ }
+ if (n > ntohs(thisHdr.size))
+ {
+ QMessageBox::information(NULL,
+ PROGNAME,
+ QString("Error in link\nOffset too big")
+ );
+ return false;
+ }
+ qDebug("Hyper:<%u,%u>", tuid, n);
+ while (bufferpos < n && bufferpos < buffercontent) getch();
+ }
+ return true;
+ }
+}
+*/
bool CPlucker::expand(int thisrec)
{
mystyle.unset();
@@ -352,58 +856,42 @@ bool CPlucker::expand(int thisrec)
CPlucker_dataRecord thisHdr;
while (1)
{
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
-// qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(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);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+// qDebug("This (%d) type is %d, uid is %u", thisrec, thisHdr.type, ntohs(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 = ntohs(thisHdr.nParagraphs);
-// qDebug("It has %u paragraphs and is %u bytes", htons(thisHdr.nParagraphs), htons(thisHdr.size));
+// qDebug("It has %u paragraphs and is %u bytes", ntohs(thisHdr.nParagraphs), ntohs(thisHdr.size));
uid = ntohs(thisHdr.uid);
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), attrs);
+ 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), attrs);
}
if (m_nParas > 0)
{
- m_nextPara = m_ParaOffsets[0];
-// qDebug("First offset = %u", m_nextPara);
- m_nextParaIndex = 0;
+ m_nextPara = m_ParaOffsets[0];
+// qDebug("First offset = %u", m_nextPara);
+ m_nextParaIndex = 0;
}
else
{
- m_nextPara = -1;
+ m_nextPara = -1;
}
reclen -= sizeof(thisHdr)+4*m_nParas;
- buffercontent = htons(thisHdr.size);
+ buffercontent = ntohs(thisHdr.size);
- if (thisHdr.type == 0)
- {
- fread(expandedtextbuffer, reclen, sizeof(char), fin);
- }
- else
- {
- fread(compressedtextbuffer, reclen, sizeof(char), fin);
- switch (ntohs(hdr0.version))
- {
- case 2:
- UnZip(reclen, expandedtextbuffer, buffercontent);
- break;
- case 1:
- UnDoc(reclen, expandedtextbuffer, buffercontent);
- break;
- }
- }
+ Expand(reclen, thisHdr.type, expandedtextbuffer, buffercontent);
bufferpos = 0;
bufferrec = thisrec;
// qDebug("BC:%u, HS:%u", buffercontent, ntohs(thisHdr.size));
@@ -440,6 +928,8 @@ void CPlucker::UnZip(size_t reclen, UInt8* tgtbuffer, UInt16 bsize)
err = inflate( &zstream, Z_SYNC_FLUSH );
+// qDebug("err:%d - %u", err, zstream.avail_in);
+
} while ( err == Z_OK );
inflateEnd(&zstream);
@@ -511,69 +1001,241 @@ CList<Bkmk>* CPlucker::getbkmklist()
for (int i = 1; i < ntohs(head.recordList.numRecords); i++)
{
- gotorecordnumber(i);
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
- if (thisHdr.type == 8)
- {
- UInt16 n;
- fread(&n, 1, sizeof(n), fin);
- n = ntohs(n);
- qDebug("Found %u bookmarks", n);
- }
- qDebug("Found:%d, %u", i , thisHdr.type);
+ gotorecordnumber(i);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ if (thisHdr.type == 8)
+ {
+ UInt16 n;
+ fread(&n, 1, sizeof(n), fin);
+ n = ntohs(n);
+ qDebug("Found %u bookmarks", n);
+ }
+ qDebug("Found:%d, %u", i , thisHdr.type);
}
*/
return NULL;
}
-void CPlucker::expandimg(UInt16 tgt)
+QImage* CPlucker::getimg(UInt16 tgt)
{
- qDebug("Image:%u", tgt);
+// static int imageno;
+// char* file = "tmp1";
+// sprintf(file, "image%04u.tbmp", imageno++);
+// qDebug("Image:%u", tgt);
CPlucker_dataRecord thisHdr;
size_t reclen;
+ UInt16 thisrec = finduid(tgt);
+ reclen = recordlength(thisrec);
+ gotorecordnumber(thisrec);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+/*
UInt16 thisrec = 0;
do
{
- thisrec++;
- reclen = recordlength(thisrec);
- gotorecordnumber(thisrec);
- qDebug("thisrec:%u.%u", ftell(fin),thisrec);
- fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ hthisrec++;
+ reclen = recordlength(thisrec);
+ gotorecordnumber(thisrec);
+// qDebug("thisrec:%u.%u", ftell(fin),thisrec);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
}
while (ntohs(thisHdr.uid) != tgt);
-
+*/
reclen -= sizeof(thisHdr);
- UInt16 imgsize = htons(thisHdr.size);
+ UInt16 imgsize = ntohs(thisHdr.size);
UInt8* imgbuffer = new UInt8[imgsize];
- qDebug("type:%u", thisHdr.type);
+// qDebug("type:%u", thisHdr.type);
+ Expand(reclen, thisHdr.type, imgbuffer, imgsize);
- if (thisHdr.type == 2)
+ QImage* qimage = Palm2QImage(imgbuffer, imgsize);
+
+ delete [] imgbuffer;
+
+ return qimage;
+}
+
+#include <qnamespace.h>
+
+QPixmap* CPlucker::expandimg(UInt16 tgt, bool border)
+{
+ QImage* qimage = getimg(tgt);
+ if (qimage == NULL) return NULL;
+ QPixmap* image = new QPixmap(0,0);
+ QPixmap* ret;
+// qDebug("New image");
+ image->convertFromImage(*qimage);
+ delete qimage;
+ if (border)
{
- qDebug("Not compressed:%u.%u", ftell(fin),reclen);
- fread(imgbuffer, reclen, sizeof(char), fin);
- qDebug("Not compressed:%u.%u", ftell(fin),reclen);
+ ret = new QPixmap(image->width()+4, image->height()+4);
+ ret->fill(Qt::red);
+ bitBlt(ret, 2, 2, image, 0, 0, -1, -1);//, Qt::RasterOp::CopyROP);
+ delete image;
}
else
{
- qDebug("Compressed");
- fread(compressedtextbuffer, reclen, sizeof(char), fin);
- switch (ntohs(hdr0.version))
- {
- case 2:
- UnZip(reclen, imgbuffer, imgsize);
- break;
- case 1:
- UnDoc(reclen, imgbuffer, imgsize);
- break;
- }
+ ret = image;
}
- FILE* imgfile = fopen("/home/tim/newreader/imagefile.tbmp", "w");
- if (imgfile != NULL)
+ return ret;
+}
+
+#ifdef _BUFFERPICS
+#include <qmap.h>
+#endif
+
+QPixmap* CPlucker::getPicture(unsigned long tgt)
+{
+#ifdef _BUFFERPICS
+ static QMap<unsigned long, QPixmap> pix;
+ QMap<unsigned long, QPixmap>::Iterator t = pix.find(tgt);
+ if (t == pix.end())
{
- fwrite(imgbuffer, 1, imgsize, imgfile);
- fclose(imgfile);
+ pix[tgt] = *expandimg(tgt);
+ return &pix[tgt];
}
- delete [] imgbuffer;
+ else
+ return &(t.data());
+#else
+ return expandimg(tgt);
+#endif
+}
+
+#ifdef LOCALPICTURES
+#include <unistd.h>
+#include <qpe/global.h>
+void CPlucker::showimg(UInt16 tgt)
+{
+ qDebug("Crassssssh!");
+ QPixmap* qimage = expandimg(tgt);
+ m_picture->setFixedSize(qimage->size());
+ m_picture->setBackgroundPixmap(*qimage);
+ delete qimage;
+ m_viewer->show();
+
+/*
+ char tmp[] = "uqtreader.XXXXXX";
+ QImage* qimage = getimg(tgt);
+ QPixmap* image = new QPixmap(0,0);
+// qDebug("New image");
+ image->convertFromImage(*qimage);
+ delete qimage;
+ char tmpfile[sizeof(tmp)+1];
+ strcpy(tmpfile,tmp);
+ int f = mkstemp(tmpfile);
+ close(f);
+ qDebug("TMPFILE:%s", tmpfile);
+ if (image->save(tmpfile,"PNG"))
+ {
+ QCopEnvelope e("QPE/Application/showimg", "setDocument(QString)");
+ e << QString(tmpfile);
+ }
+ Global::statusMessage("Opening image");
+ sleep(5);
+ delete image;
+ unlink(tmpfile);
+*/
+}
+
+#endif
+
+void CPlucker::setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
+{
+ unsigned short sz = 0;
+ for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
+ {
+ sz++;
+ }
+ size_t newlen = srclen+sizeof(sz)+sz*sizeof(unsigned long);
+ unsigned char* newdata = new unsigned char[newlen];
+ unsigned char* pdata = newdata;
+ memcpy(newdata, src, srclen);
+ newdata += srclen;
+ memcpy(newdata, &sz, sizeof(sz));
+ newdata += sizeof(sz);
+ for (CList<unsigned long>::iterator it = visited.begin(); it != visited.end(); it++)
+ {
+ unsigned long t = *it;
+ qDebug("[%u]", t);
+ memcpy(newdata, &t, sizeof(t));
+ newdata += sizeof(t);
+ }
+ m_nav.setSaveData(data, len, pdata, newlen);
+ delete [] pdata;
+}
+
+void CPlucker::putSaveData(unsigned char*& src, unsigned short& srclen)
+{
+ unsigned short sz;
+ if (srclen >= sizeof(sz))
+ {
+ memcpy(&sz, src, sizeof(sz));
+ src += sizeof(sz);
+ srclen -= sizeof(sz);
+ }
+ for (int i = 0; i < sz; i++)
+ {
+ unsigned long t;
+ if (srclen >= sizeof(t))
+ {
+ memcpy(&t, src, sizeof(t));
+ qDebug("[%u]", t);
+ visited.push_front(t);
+ src += sizeof(t);
+ srclen -= sizeof(t);
+ }
+ else
+ {
+ QMessageBox::warning(NULL, PROGNAME, "File data mismatch\nMight fix itself");
+ break;
+ }
+ }
+ m_nav.putSaveData(src, srclen);
+}
+
+unsigned short CPlucker::finduid(unsigned short urlid)
+{
+// qDebug("Finding %u", urlid);
+ unsigned short jmin = 1, jmax = ntohs(head.recordList.numRecords);
+ unsigned short jmid = (jmin+jmax) >> 1;
+ while (jmax - jmin > 1)
+ {
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(jmid);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ unsigned short luid = ntohs(thisHdr.uid);
+// qDebug("%u %u %u : %u", jmin, jmid, jmax, urlid);
+ if (luid == urlid)
+ {
+ return jmid;
+ }
+ if (luid < urlid)
+ {
+ jmin = jmid;
+ }
+ else
+ {
+ jmax = jmid;
+ }
+ jmid = (jmin+jmax) >> 1;
+ }
+ CPlucker_dataRecord thisHdr;
+ gotorecordnumber(jmin);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ unsigned short luid = ntohs(thisHdr.uid);
+ qDebug("jmin at end:%u,%u", jmin, luid);
+ if (luid == urlid)
+ {
+ return jmin;
+ }
+ gotorecordnumber(jmax);
+ fread(&thisHdr, 1, sizeof(thisHdr), fin);
+ luid = ntohs(thisHdr.uid);
+ qDebug("jmax at end:%u,%u", jmax, luid);
+ if (luid == urlid)
+ {
+ return jmax;
+ }
+ qDebug("Couldn't find %u", urlid);
+ return 0; // Not found!
}
diff --git a/noncore/apps/opie-reader/plucker.h b/noncore/apps/opie-reader/plucker.h
index d3ca732..083eac6 100644
--- a/noncore/apps/opie-reader/plucker.h
+++ b/noncore/apps/opie-reader/plucker.h
@@ -6,6 +6,13 @@
#include "ztxt.h"
#include "pdb.h"
#include "CBuffer.h"
+#include "Navigation.h"
+#include "my_list.h"
+
+#ifdef LOCALPICTURES
+class QScrollView;
+class QWidget;
+#endif
struct CPlucker_dataRecord
{
@@ -29,13 +36,22 @@ struct CPluckerbkmk
tchar title[MAX_BMRK_LENGTH];
};
-
const UInt32 CPLUCKER_ID = 0x5458547a;
class CPlucker : public CExpander, Cpdb
{
- size_t textlength;
+ unsigned short finduid(unsigned short);
+ char* geturl(UInt16);
+ void Expand(UInt16, UInt8, UInt8*, UInt16);
+ CList<unsigned long> visited;
+ bool m_lastIsBreak;
+#ifdef LOCALPICTURES
+ QScrollView* m_viewer;
+ QWidget* m_picture;
+#endif
+ size_t textlength, m_lastBreak;
UInt16 uid;
+ UInt8 EOPPhase;
int m_nextPara, m_nextParaIndex;
CBufferFace<UInt16> m_ParaOffsets;
CBufferFace<UInt16> m_ParaAttrs;
@@ -46,6 +62,8 @@ class CPlucker : public CExpander, Cpdb
UInt32 buffercontent;
UInt8* expandedtextbuffer;
UInt8* compressedtextbuffer;
+ char* urls;
+ size_t urlsize;
size_t bufferpos;
UInt16 bufferrec;
CPlucker_record0 hdr0;
@@ -53,24 +71,29 @@ class CPlucker : public CExpander, Cpdb
bool expand(int);
void UnZip(size_t, UInt8*, UInt16);
void UnDoc(size_t, UInt8*, UInt16);
- void expandimg(UInt16 tgt);
+#ifdef LOCALPICTURES
+ void showimg(UInt16 tgt);
+#endif
+ QImage* getimg(UInt16 tgt);
+ QPixmap* expandimg(UInt16 tgt, bool border=false);
void home();
int bgetch();
+ CNavigation m_nav;
public:
- virtual void sizes(unsigned long& _file, unsigned long& _text)
- {
- _file = file_length;
- _text = textlength;
-//ntohl(hdr0.size);
- }
+ virtual void suspend()
+ {
+ CExpander::suspend(fin);
+ }
+ virtual void unsuspend()
+ {
+ CExpander::unsuspend(fin);
+ }
+ virtual QPixmap* getPicture(unsigned long tgt);
+ virtual void sizes(unsigned long& _file, unsigned long& _text);
virtual bool hasrandomaccess() { return true; }
- virtual ~CPlucker()
- {
- if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
- if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
- }
+ virtual ~CPlucker();
CPlucker();
- virtual int openfile(const char *src);
+ virtual int OpenFile(const char *src);
virtual int getch();
virtual void getch(int&, CStyle&);
virtual unsigned int locate();
@@ -78,9 +101,23 @@ class CPlucker : public CExpander, Cpdb
virtual CList<Bkmk>* getbkmklist();
virtual bool hyperlink(unsigned int n);
virtual MarkupType PreferredMarkup()
- {
- return cNONE;
- }
+ {
+ return cNONE;
+ }
+ void saveposn(size_t posn) { m_nav.saveposn(posn); }
+ bool forward(size_t& loc) { return m_nav.forward(loc); }
+ bool back(size_t& loc) { return m_nav.back(loc); }
+ bool hasnavigation() { return true; }
+ unsigned long startSection()
+ {
+ return currentpos-bufferpos;
+ }
+ unsigned long endSection()
+ {
+ return startSection()+buffercontent;
+ }
+ void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen);
+ void putSaveData(unsigned char*& src, unsigned short& srclen);
};
#endif
diff --git a/noncore/apps/opie-reader/ppm_expander.cpp b/noncore/apps/opie-reader/ppm_expander.cpp
index 4f0a277..fe2745c 100644
--- a/noncore/apps/opie-reader/ppm_expander.cpp
+++ b/noncore/apps/opie-reader/ppm_expander.cpp
@@ -35,7 +35,7 @@ ppm_expander::~ppm_expander() {
if (my_file_in != NULL) fclose(my_file_in);
}
-int ppm_expander::openfile(const char* infile)
+int ppm_expander::OpenFile(const char* infile)
{
my_file_in=fopen(infile,"rb");
my_read_buf = new PPM_ReadBuf(my_file_in);
diff --git a/noncore/apps/opie-reader/ppm_expander.h b/noncore/apps/opie-reader/ppm_expander.h
index 115988d..4278c82 100644
--- a/noncore/apps/opie-reader/ppm_expander.h
+++ b/noncore/apps/opie-reader/ppm_expander.h
@@ -25,7 +25,15 @@ class ppm_expander : public CExpander {
FILE* my_file_in;
PPM_ReadBuf* my_read_buf;
ppm_worker ppm;
- public:
+public:
+ virtual void suspend()
+ {
+ CExpander::suspend(my_file_in);
+ }
+ virtual void unsuspend()
+ {
+ CExpander::unsuspend(my_file_in);
+ }
ppm_expander() : needppmend(false), my_file_in(NULL), my_read_buf(NULL)
{
bufsize = 1024;
@@ -33,7 +41,7 @@ class ppm_expander : public CExpander {
buf_out = new UCHAR[bufsize];
outbytes = 0;
}
- virtual int openfile(const char* infile);
+ virtual int OpenFile(const char* infile);
virtual int getch();
int locate(unsigned short block, unsigned int n);
virtual ~ppm_expander();
diff --git a/noncore/apps/opie-reader/ustring.h b/noncore/apps/opie-reader/ustring.h
index a4dc048..a3ef8df 100644
--- a/noncore/apps/opie-reader/ustring.h
+++ b/noncore/apps/opie-reader/ustring.h
@@ -63,6 +63,18 @@ inline QString toQString(tchar *_p, unsigned int len)
while (*p != 0 && i < len) ret[i++] = *(p++);
return ret;
}
+
+inline tchar* fromQString(const QString& qs)
+{
+ int len = qs.length();
+ tchar* ret = new tchar[len+1];
+ for (int i = 0; i < len; i++)
+ {
+ ret[i] = qs[i].unicode();
+ }
+ ret[len] = 0;
+ return ret;
+}
#else
inline size_t ustrlen(const tchar* _p) { return strlen(_p); }
diff --git a/noncore/apps/opie-reader/version.h b/noncore/apps/opie-reader/version.h
index 8b6c756..003e9db 100644
--- a/noncore/apps/opie-reader/version.h
+++ b/noncore/apps/opie-reader/version.h
@@ -1,5 +1,5 @@
#define MAJOR 0
-#define BKMKTYPE 5
+#define BKMKTYPE 6
#define MINOR 'a'
#define RELEASE_TYPE "beta"
diff --git a/noncore/apps/opie-reader/ztxt.cpp b/noncore/apps/opie-reader/ztxt.cpp
index 289b13a..8091d32 100644
--- a/noncore/apps/opie-reader/ztxt.cpp
+++ b/noncore/apps/opie-reader/ztxt.cpp
@@ -7,7 +7,7 @@
ztxt::ztxt() : bInit(false), expandedtextbuffer(NULL), compressedtextbuffer(NULL) { /*printf("constructing:%x\n",fin);*/ }
-int ztxt::openfile(const char *src)
+int ztxt::OpenFile(const char *src)
{
if (!Cpdb::openfile(src))
{
diff --git a/noncore/apps/opie-reader/ztxt.h b/noncore/apps/opie-reader/ztxt.h
index 20558a6..d7cb96a 100644
--- a/noncore/apps/opie-reader/ztxt.h
+++ b/noncore/apps/opie-reader/ztxt.h
@@ -74,32 +74,40 @@ class ztxt : public CExpander, Cpdb
zTXT_record0 hdr0;
size_t currentpos;
void home();
- public:
+public:
+ virtual void suspend()
+ {
+ CExpander::suspend(fin);
+ }
+ virtual void unsuspend()
+ {
+ CExpander::unsuspend(fin);
+ }
virtual void sizes(unsigned long& _file, unsigned long& _text)
- {
- _file = file_length;
- _text = ntohl(hdr0.size);
- }
+ {
+ _file = file_length;
+ _text = ntohl(hdr0.size);
+ }
virtual bool hasrandomaccess() { return (hdr0.randomAccess != 0); }
virtual ~ztxt()
- {
- if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
- if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
- if (bInit)
- {
- inflateEnd(&zstream);
- }
- }
+ {
+ if (expandedtextbuffer != NULL) delete [] expandedtextbuffer;
+ if (compressedtextbuffer != NULL) delete [] compressedtextbuffer;
+ if (bInit)
+ {
+ inflateEnd(&zstream);
+ }
+ }
ztxt();
- virtual int openfile(const char *src);
+ virtual int OpenFile(const char *src);
virtual int getch();
virtual unsigned int locate();
virtual void locate(unsigned int n);
virtual CList<Bkmk>* getbkmklist();
virtual MarkupType PreferredMarkup()
- {
- return cTEXT;
- }
+ {
+ return cTEXT;
+ }
};
#endif