~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/backend/cdisplayrendering.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: cdisplayrendering
 
3
//
 
4
// Description:
 
5
//
 
6
//
 
7
// Author: The BibleTime team <info@bibletime.info>, (C) 2004
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
 
 
13
//Backend includes
 
14
#include "cdisplayrendering.h"
 
15
 
 
16
#include "cdisplaytemplatemgr.h"
 
17
#include "creferencemanager.h"
 
18
#include "cswordkey.h"
 
19
#include "cswordversekey.h"
 
20
 
 
21
//Qt includes
 
22
#include <qstring.h>
 
23
#include <qregexp.h>
 
24
 
 
25
namespace Rendering {
 
26
 
 
27
        CDisplayRendering::CDisplayRendering(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions)
 
28
: CHTMLExportRendering(CHTMLExportRendering::Settings(true), displayOptions, filterOptions) {}
 
29
 
 
30
        const QString CDisplayRendering::entryLink( const KeyTreeItem& item, CSwordModuleInfo*  module ) {
 
31
                QString linkText;
 
32
 
 
33
                const bool isBible = module && (module->type() == CSwordModuleInfo::Bible);
 
34
                CSwordVerseKey vk(module); //only valid for bible modules, i.e. isBible == true
 
35
                vk.Headings(true);
 
36
 
 
37
                if (isBible) {
 
38
                        vk = item.key();
 
39
                }
 
40
 
 
41
                if (isBible && (vk.Verse() == 0)) {
 
42
                        return QString::null; //Warning: return already here
 
43
                }
 
44
 
 
45
                switch (item.settings().keyRenderingFace) {
 
46
 
 
47
                        case KeyTreeItem::Settings::NoKey: {
 
48
                                linkText = QString::null;
 
49
                                break; //no key is valid for all modules
 
50
                        }
 
51
 
 
52
                        case KeyTreeItem::Settings::CompleteShort: {
 
53
                                if (isBible) {
 
54
                                        linkText = QString::fromUtf8(vk.getShortText());
 
55
                                        break;
 
56
                                }
 
57
 
 
58
                                //fall through for non-Bible modules
 
59
                        }
 
60
 
 
61
                        case KeyTreeItem::Settings::CompleteLong: {
 
62
                                if (isBible) {
 
63
                                        linkText = vk.key();
 
64
                                        break;
 
65
                                }
 
66
 
 
67
                                //fall through for non-Bible modules
 
68
                        }
 
69
 
 
70
                        case KeyTreeItem::Settings::SimpleKey: {
 
71
                                if (isBible) {
 
72
                                        linkText = QString::number(vk.Verse());
 
73
                                        break;
 
74
                                }
 
75
 
 
76
                                //fall through for non-Bible modules
 
77
                        }
 
78
 
 
79
                        default: { //default behaviour to return the passed key
 
80
                                linkText = item.key();
 
81
                                break;
 
82
                        }
 
83
                }
 
84
 
 
85
                if (linkText.isEmpty()) {
 
86
                        return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" />");
 
87
                }
 
88
                else {
 
89
                        return QString("<a name=\"").append(keyToHTMLAnchor(item.key())).append("\" ")
 
90
                                   .append("href=\"")
 
91
                                   .append(CReferenceManager::encodeHyperlink(
 
92
                                                           module->name(), item.key(), CReferenceManager::typeFromModule(module->type()))
 
93
                                                  )
 
94
                                   .append("\">").append(linkText).append("</a>\n");
 
95
                }
 
96
 
 
97
                return QString::null;
 
98
        }
 
99
 
 
100
        const QString CDisplayRendering::keyToHTMLAnchor(const QString& key) {
 
101
                QString ret = key;
 
102
                ret = ret.stripWhiteSpace().remove(QRegExp("[^A-Za-z0-9]+"));
 
103
                ret = ret.remove(QRegExp("^\\d+|"));
 
104
 
 
105
                return ret;
 
106
        }
 
107
 
 
108
        const QString CDisplayRendering::finishText( const QString& oldText, KeyTree& tree ) {
 
109
                ListCSwordModuleInfo modules = tree.collectModules();
 
110
 
 
111
 
 
112
                //marking words is very slow, we have to find a better solution
 
113
 
 
114
                /*
 
115
                 //mark all words by spans
 
116
 
 
117
                 QString text = oldText;
 
118
 
 
119
                 QRegExp re("(\\b)(?=\\w)"); //word begin marker
 
120
                 int pos = text.find(re, 0);
 
121
 
 
122
                 while (pos != -1) { //word begin found
 
123
                  //qWarning("found word at %i in %i", pos, text.length());
 
124
                  int endPos = pos + 1;
 
125
                  if (!CToolClass::inHTMLTag(pos+1, text)) { //the re has a positive look ahead which matches one char before the word start
 
126
                   //qWarning("matched %s", text.mid(pos+1, 4).latin1());
 
127
 
 
128
                   //find end of word and put a marker around it
 
129
                   endPos = text.find(QRegExp("\\b|[,.:]"), pos+1);
 
130
                   if ((endPos != -1) && !CToolClass::inHTMLTag(endPos, text) && (endPos - pos >= 3)) { //reuire wordslonger than 3 chars
 
131
                    text.insert(endPos, "</span>");
 
132
                    text.insert(pos, "<span class=\"word\">");
 
133
 
 
134
                    endPos += 26;
 
135
                   }
 
136
                  }
 
137
                  pos = text.find(re, endPos);
 
138
                 }
 
139
                */
 
140
                const CLanguageMgr::Language* const lang =
 
141
                        (modules.count() >= 1)
 
142
                        ? modules.first()->language()
 
143
                        : CPointers::languageMgr()->defaultLanguage();
 
144
 
 
145
                CDisplayTemplateMgr* tMgr = CPointers::displayTemplateManager();
 
146
 
 
147
                Q_ASSERT(modules.count() >= 1);
 
148
 
 
149
                CDisplayTemplateMgr::Settings settings;
 
150
                settings.modules = modules;
 
151
                settings.langAbbrev = ((modules.count() == 1) && lang->isValid())
 
152
                                                          ? lang->abbrev()
 
153
                                                          : QString::null;
 
154
                settings.pageDirection = (modules.count() == 1)
 
155
                                                                 ? ((modules.first()->textDirection() == CSwordModuleInfo::LeftToRight) ? "ltr"  : "rtl")
 
156
                                                 : QString::null;
 
157
 
 
158
                return tMgr->fillTemplate(CBTConfig::get
 
159
                                                                          (CBTConfig::displayStyle), oldText, settings);
 
160
 
 
161
 
 
162
        }
 
163
}