Diffstat (limited to 'noncore/apps/opie-reader/BuffDoc.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/BuffDoc.cpp | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/noncore/apps/opie-reader/BuffDoc.cpp b/noncore/apps/opie-reader/BuffDoc.cpp index 1f0a524..355d14d 100644 --- a/noncore/apps/opie-reader/BuffDoc.cpp +++ b/noncore/apps/opie-reader/BuffDoc.cpp | |||
@@ -1,39 +1,39 @@ | |||
1 | #include "names.h" | 1 | #include "names.h" |
2 | 2 | ||
3 | #define NEWLINEBREAK | 3 | #define NEWLINEBREAK |
4 | #define INCREMENTALWIDTH | 4 | #define INCREMENTALWIDTH |
5 | 5 | ||
6 | #include "usenef.h" | ||
7 | #include "BuffDoc.h" | 6 | #include "BuffDoc.h" |
8 | #include "config.h" | 7 | #include "config.h" |
9 | #include "CDrawBuffer.h" | 8 | #include "CDrawBuffer.h" |
10 | #include "ZText.h" | 9 | #include "ZText.h" |
11 | #include "ebookcodec.h" | 10 | #include "ebookcodec.h" |
12 | 11 | ||
13 | #ifdef __STATIC | 12 | #ifdef __STATIC |
14 | #include "Aportis.h" | 13 | #include "Aportis.h" |
15 | #include "CHM.h" | 14 | #include "CHM.h" |
16 | #include "ppm_expander.h" | 15 | #include "ppm_expander.h" |
17 | #include "ztxt.h" | 16 | #include "ztxt.h" |
18 | #include "plucker.h" | 17 | #include "plucker.h" |
19 | #ifdef USENEF | 18 | #ifdef USENEF |
20 | #include "nef.h" | 19 | #include "nef.h" |
21 | #include "arrierego.h" | 20 | #include "arrierego.h" |
22 | #endif | 21 | #endif |
23 | #include "iSilo.h" | 22 | #include "iSilo.h" |
23 | #include "Reb.h" | ||
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | 26 | ||
27 | linkType BuffDoc::hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) | 27 | linkType BuffDoc::hyperlink(unsigned int n, unsigned int noff, QString& wrd, QString& nm) |
28 | { | 28 | { |
29 | linkType bRet = eNone; | 29 | linkType bRet = eNone; |
30 | if (exp != NULL) | 30 | if (exp != NULL) |
31 | { | 31 | { |
32 | bRet = filt->hyperlink(n, noff, wrd, nm); | 32 | bRet = filt->hyperlink(n, noff, wrd, nm); |
33 | if ((bRet & eLink) != 0) | 33 | if ((bRet & eLink) != 0) |
34 | { | 34 | { |
35 | lastword.empty(); | 35 | lastword.empty(); |
36 | lastsizes[0] = laststartline = n; | 36 | lastsizes[0] = laststartline = n; |
37 | #ifdef NEWLINEBREAK | 37 | #ifdef NEWLINEBREAK |
38 | lastispara = false; | 38 | lastispara = false; |
39 | #else | 39 | #else |
@@ -47,32 +47,44 @@ linkType BuffDoc::hyperlink(unsigned int n, unsigned int noff, QString& wrd, QSt | |||
47 | 47 | ||
48 | void BuffDoc::locate(unsigned int n) | 48 | void BuffDoc::locate(unsigned int n) |
49 | { | 49 | { |
50 | // //qDebug("BuffDoc:locating:%u",n); | 50 | // //qDebug("BuffDoc:locating:%u",n); |
51 | lastword.empty(); | 51 | lastword.empty(); |
52 | lastsizes[0] = laststartline = n; | 52 | lastsizes[0] = laststartline = n; |
53 | #ifdef NEWLINEBREAK | 53 | #ifdef NEWLINEBREAK |
54 | lastispara = false; | 54 | lastispara = false; |
55 | #else | 55 | #else |
56 | lastispara = false; | 56 | lastispara = false; |
57 | #endif | 57 | #endif |
58 | // tchar linebuf[1024]; | 58 | // tchar linebuf[1024]; |
59 | if (exp != NULL) filt->locate(n); | 59 | if (exp != NULL) filt->locate(n); |
60 | // //qDebug("BuffDoc:Located"); | 60 | // //qDebug("BuffDoc:Located"); |
61 | } | 61 | } |
62 | 62 | ||
63 | void BuffDoc::resetPos() | ||
64 | { | ||
65 | // //qDebug("BuffDoc:locating:%u",n); | ||
66 | lastword.empty(); | ||
67 | lastsizes[0] = laststartline = exp->locate(); | ||
68 | #ifdef NEWLINEBREAK | ||
69 | lastispara = false; | ||
70 | #else | ||
71 | lastispara = false; | ||
72 | #endif | ||
73 | } | ||
74 | |||
63 | static bool isletter(unsigned short c) | 75 | static bool isletter(unsigned short c) |
64 | { | 76 | { |
65 | if ('a' <= c && c <= 'z') return true; | 77 | if ('a' <= c && c <= 'z') return true; |
66 | if ('A' <= c && c <= 'Z') return true; | 78 | if ('A' <= c && c <= 'Z') return true; |
67 | // Cyrillic letters | 79 | // Cyrillic letters |
68 | if (0x400 <= c && c <= 0x52F) return true; | 80 | if (0x400 <= c && c <= 0x52F) return true; |
69 | return false; | 81 | return false; |
70 | } | 82 | } |
71 | 83 | ||
72 | static bool isvowel(unsigned short c) // Only want lower case vowels | 84 | static bool isvowel(unsigned short c) // Only want lower case vowels |
73 | { | 85 | { |
74 | switch (c) | 86 | switch (c) |
75 | { | 87 | { |
76 | case 'a': | 88 | case 'a': |
77 | case 'e': | 89 | case 'e': |
78 | case 'i': | 90 | case 'i': |
@@ -622,53 +634,70 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
622 | 634 | ||
623 | delete exp; | 635 | delete exp; |
624 | exp = new CHM; | 636 | exp = new CHM; |
625 | ret = exp->openfile(src); | 637 | ret = exp->openfile(src); |
626 | } | 638 | } |
627 | if (ret != 0) | 639 | if (ret != 0) |
628 | { | 640 | { |
629 | 641 | ||
630 | delete exp; | 642 | delete exp; |
631 | exp = new iSilo; | 643 | exp = new iSilo; |
632 | ret = exp->openfile(src); | 644 | ret = exp->openfile(src); |
633 | } | 645 | } |
634 | if (ret != 0) | 646 | if (ret != 0) |
635 | { | 647 | { |
636 | delete exp; | 648 | delete exp; |
637 | //qDebug("Trying ppms"); | 649 | //qDebug("Trying ppms"); |
650 | exp = new CReb; | ||
651 | ret = exp->openfile(src); | ||
652 | } | ||
653 | if (ret != 0) | ||
654 | { | ||
655 | delete exp; | ||
656 | //qDebug("Trying ppms"); | ||
638 | exp = new ppm_expander; | 657 | exp = new ppm_expander; |
639 | ret = exp->openfile(src); | 658 | ret = exp->openfile(src); |
640 | } | 659 | } |
641 | if (ret != 0) | 660 | if (ret != 0) |
642 | { | 661 | { |
643 | delete exp; | 662 | delete exp; |
644 | exp = new Text; | 663 | exp = new Text; |
645 | // //qDebug("Trying text"); | 664 | // //qDebug("Trying text"); |
646 | ret = exp->openfile(src); | 665 | ret = exp->openfile(src); |
647 | if (ret == 0) qDebug("Text format"); | 666 | if (ret == 0) qDebug("Text format"); |
648 | } | 667 | } |
649 | 668 | ||
650 | if (ret != 0) | 669 | if (ret != 0) |
651 | { | 670 | { |
652 | delete exp; | 671 | delete exp; |
653 | QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file"); | 672 | QMessageBox::information(_parent, PROGNAME, "Unknown file compression type","Try another file"); |
654 | return ret; | 673 | return ret; |
655 | } | 674 | } |
656 | // //qDebug("Doing final open:%x:%x",exp,filt); | 675 | // //qDebug("Doing final open:%x:%x",exp,filt); |
657 | #else | 676 | #else |
658 | QString codecpath(QTReaderUtil::getPluginPath()); | 677 | #ifdef USEQPE |
678 | #ifdef OPIE | ||
679 | QString codecpath(getenv("OPIEDIR")); | ||
680 | #else | ||
681 | QString codecpath(getenv("QTDIR")); | ||
682 | #endif | ||
683 | codecpath += "/plugins/reader/codecs"; | ||
684 | #else | ||
685 | QString codecpath(getenv("READERDIR")); | ||
686 | codecpath += "/codecs"; | ||
687 | #endif | ||
659 | QDir d(codecpath, "*.so"); | 688 | QDir d(codecpath, "*.so"); |
660 | 689 | ||
661 | if (d.exists()) | 690 | if (d.exists()) |
662 | { | 691 | { |
663 | 692 | ||
664 | const QFileInfoList *list = d.entryInfoList(); | 693 | const QFileInfoList *list = d.entryInfoList(); |
665 | QFileInfoListIterator it( *list ); // create list iterator | 694 | QFileInfoListIterator it( *list ); // create list iterator |
666 | QFileInfo *fi; // pointer for traversing | 695 | QFileInfo *fi; // pointer for traversing |
667 | 696 | ||
668 | int ret = -1; | 697 | int ret = -1; |
669 | while ( ret != 0 && (fi=it.current()) ) | 698 | while ( ret != 0 && (fi=it.current()) ) |
670 | { // for each file... | 699 | { // for each file... |
671 | if (exp != NULL) delete exp; | 700 | if (exp != NULL) delete exp; |
672 | qDebug("Trying %s", (const char*)fi->fileName()); | 701 | qDebug("Trying %s", (const char*)fi->fileName()); |
673 | exp = new ebookcodec(fi->fileName()); | 702 | exp = new ebookcodec(fi->fileName()); |
674 | ret = exp->openfile(src); | 703 | ret = exp->openfile(src); |
@@ -693,16 +722,38 @@ int BuffDoc::openfile(QWidget* _parent, const char *src) | |||
693 | lastsizes[0] = laststartline = 0; | 722 | lastsizes[0] = laststartline = 0; |
694 | #ifdef NEWLINEBREAK | 723 | #ifdef NEWLINEBREAK |
695 | lastispara = false; | 724 | lastispara = false; |
696 | #else | 725 | #else |
697 | lastispara = false; | 726 | lastispara = false; |
698 | #endif | 727 | #endif |
699 | exp->locate(exp->getHome()); | 728 | exp->locate(exp->getHome()); |
700 | filt->setsource(exp); | 729 | filt->setsource(exp); |
701 | qDebug("BuffDoc:file opened"); | 730 | qDebug("BuffDoc:file opened"); |
702 | return 0; | 731 | return 0; |
703 | } | 732 | } |
704 | 733 | ||
705 | QString BuffDoc::about() | 734 | QString BuffDoc::about() |
706 | { | 735 | { |
707 | return QString("Buffered Decompressor (c) Tim Wentford\nHyphenation algorithm (c) Tim Wentford\n (Cyrillic support by Konstantin Isakov\n")+filt->about(); | 736 | return QString("Buffered Decompressor (c) Tim Wentford\nHyphenation algorithm (c) Tim Wentford\n (Cyrillic support by Konstantin Isakov\n")+filt->about(); |
708 | } | 737 | } |
738 | |||
739 | int BuffDoc::getsentence(CBuffer& buff) | ||
740 | { | ||
741 | tchar ch; | ||
742 | int i = 0; | ||
743 | bool intext = false; | ||
744 | while ((ch = getch()) != 10 && ch != UEOF) | ||
745 | { | ||
746 | buff[i++] = ch; | ||
747 | if (ch == '"' || ch == '\'' || ch == 0x2018 || ch == 0x2019 || | ||
748 | ch == 0x201a || ch == 0x201b || ch == 0x201c || ch == 0x201d) | ||
749 | { | ||
750 | intext = !intext; | ||
751 | } | ||
752 | if (!intext && (ch == '.' || ch == '!' || ch == '?')) break; | ||
753 | } | ||
754 | |||
755 | buff[i] = '\0'; | ||
756 | if (i == 0 && ch == UEOF) i = -1; | ||
757 | laststartline = exp->locate(); | ||
758 | return i; | ||
759 | } | ||