Improve sword bible integration to get first preverse and multiple verses
[kworship.git] / kworship / bible / KwBibleModule.cpp
blob9a8d121d3e7ba9a19e27199ae4618698d02da334
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file KwBibleModule.cpp
22 * @brief A bible module (analagous to a SWORD module).
23 * @author James Hogan <james@albanarts.com>
26 #include "KwBibleModule.h"
28 #include <QStringList>
30 #include <swmodule.h>
31 #include <versekey.h>
34 * Constructors + destructor
37 /// Default constructor.
38 KwBibleModule::KwBibleModule(sword::SWModule* module)
39 : m_module(module)
43 /// Destructor.
44 KwBibleModule::~KwBibleModule()
49 * Main interface
52 /// Get the name of the module.
53 QString KwBibleModule::name() const
55 return m_module->Name();
58 /// Get the description of the module.
59 QString KwBibleModule::description() const
61 return m_module->Description();
64 /// Get rendered text for a given passage.
65 QString KwBibleModule::renderText(const QString& key) const
67 QStringList bits = key.split('-');
68 sword::VerseKey vkey;
69 if (bits.size() >= 2)
71 vkey = sword::VerseKey(bits[0].toAscii(), bits[1].toAscii());
73 else
75 vkey = sword::VerseKey(key.toAscii(), key.toAscii());
78 QString result;
79 sword::VerseKey verse = vkey.LowerBound();
80 verse.Headings(1);
81 sword::VerseKey last = vkey.UpperBound();
82 Q_ASSERT(verse.isTraversable());
84 int limit = 100;
85 for (; verse.compare(last) <= 0; verse.increment(1))
87 m_module->setKey(&verse);
88 m_module->RenderText();
89 const char* preverse = m_module->getEntryAttributes()["Heading"]["Preverse"]["0"];
90 result += " ";
91 if (preverse[0] != '\0')
93 result += QString("<h1>%1</h1>").arg(QString::fromUtf8(preverse));
95 result += QString("<sup>%1</sup>").arg(verse.Verse()) + QString::fromUtf8(m_module->RenderText());
96 if (0 == --limit)
98 break;
102 return result;