From a273d5787348b7b80163d54a96e80860e8e9573e Mon Sep 17 00:00:00 2001 From: James Hogan Date: Mon, 22 Dec 2008 23:29:14 +0000 Subject: [PATCH] Finished (for now) filling of bible passage and now renders html from it bible gateway parser doesn't get enough information for the bible passage struct yet --- kworship/KwBiblePlugin.cpp | 5 ++++- kworship/bible/KwBibleModule.cpp | 2 +- kworship/bible/KwBibleModule.h | 3 +++ kworship/bible/KwBibleModuleBibleGateway.cpp | 13 +++++++++++++ kworship/bible/KwBibleModuleBibleGateway.h | 3 +++ kworship/bible/KwBibleModuleSword.cpp | 24 ++++++++++++++++++++++++ kworship/bible/KwBibleModuleSword.h | 3 +++ kworship/bible/KwBiblePassage.cpp | 28 +++++++++++++++++++++++++++- 8 files changed, 78 insertions(+), 3 deletions(-) diff --git a/kworship/KwBiblePlugin.cpp b/kworship/KwBiblePlugin.cpp index a6ae152..629d8ab 100644 --- a/kworship/KwBiblePlugin.cpp +++ b/kworship/KwBiblePlugin.cpp @@ -264,7 +264,10 @@ void KwBiblePlugin::slotVerseRange() { m_comboBook->setCurrentIndex(key.start.book); m_comboChapter->setCurrentIndex(key.start.chapter); - m_textPassage->document()->setHtml(module->renderText(key)); + + KwBiblePassage passage; + module->fillPassage(key, &passage); + m_textPassage->document()->setHtml(passage.renderedText()); m_insertIntoPlaylistAction->setEnabled(true); m_showNowAction->setEnabled(true); diff --git a/kworship/bible/KwBibleModule.cpp b/kworship/bible/KwBibleModule.cpp index 36b37b5..2783736 100644 --- a/kworship/bible/KwBibleModule.cpp +++ b/kworship/bible/KwBibleModule.cpp @@ -325,7 +325,7 @@ bool KwBibleModule::fillPassage(const Key& key, KwBiblePassage* outPassage) outPassage->initChapter(book, 1+chapter, 1+firstVerse, 1+lastVerse-firstVerse); for (int verse = firstVerse; verse <= lastVerse; ++verse) { - outPassage->initVerse(book, 1+chapter, 1+verse, "heading", "content"); + fillPassageVerse(book, chapter, verse, outPassage); } } } diff --git a/kworship/bible/KwBibleModule.h b/kworship/bible/KwBibleModule.h index f4dd9a4..38cc65a 100644 --- a/kworship/bible/KwBibleModule.h +++ b/kworship/bible/KwBibleModule.h @@ -125,6 +125,9 @@ class KwBibleModule /// Fill a passage object. bool fillPassage(const Key& key, KwBiblePassage* outPassage); + /// Fill a single verse with data. + virtual bool fillPassageVerse(int bookIndex, int chapterIndex, int verseIndex, KwBiblePassage* outPassage) = 0; + /// Get rendered text for a given passage. virtual QString renderText(const Key& key) = 0; diff --git a/kworship/bible/KwBibleModuleBibleGateway.cpp b/kworship/bible/KwBibleModuleBibleGateway.cpp index 32afd26..5dc614a 100644 --- a/kworship/bible/KwBibleModuleBibleGateway.cpp +++ b/kworship/bible/KwBibleModuleBibleGateway.cpp @@ -24,6 +24,7 @@ */ #include "KwBibleModuleBibleGateway.h" +#include "KwBiblePassage.h" #include #include @@ -160,6 +161,18 @@ int KwBibleModuleBibleGateway::numVerses(int book, int chapter) } } +bool KwBibleModuleBibleGateway::fillPassageVerse(int bookIndex, int chapterIndex, int verseIndex, KwBiblePassage* outPassage) +{ + Chapter* chapter = fetchChapter(bookIndex, chapterIndex); + if (0 != chapter) + { + outPassage->initVerse(bookIndex, 1+chapterIndex, 1+verseIndex, + "", + chapter->verses[verseIndex]); + } + return false; +} + QString KwBibleModuleBibleGateway::renderText(const KwBibleModule::Key& key) { QString result; diff --git a/kworship/bible/KwBibleModuleBibleGateway.h b/kworship/bible/KwBibleModuleBibleGateway.h index 291f704..9ac309a 100644 --- a/kworship/bible/KwBibleModuleBibleGateway.h +++ b/kworship/bible/KwBibleModuleBibleGateway.h @@ -64,6 +64,9 @@ class KwBibleModuleBibleGateway : public KwBibleModule virtual int numVerses(int book, int chapter); // Reimplemented + virtual bool fillPassageVerse(int bookIndex, int chapterIndex, int verseIndex, KwBiblePassage* outPassage); + + // Reimplemented virtual QString renderText(const KwBibleModule::Key& key); protected: diff --git a/kworship/bible/KwBibleModuleSword.cpp b/kworship/bible/KwBibleModuleSword.cpp index 01d7f42..a147e91 100644 --- a/kworship/bible/KwBibleModuleSword.cpp +++ b/kworship/bible/KwBibleModuleSword.cpp @@ -24,6 +24,7 @@ */ #include "KwBibleModuleSword.h" +#include "KwBiblePassage.h" #include @@ -108,6 +109,29 @@ int KwBibleModuleSword::numVerses(int book, int chapter) return 0; } +bool KwBibleModuleSword::fillPassageVerse(int bookIndex, int chapterIndex, int verseIndex, KwBiblePassage* outPassage) +{ + int bookInTestament = -1; + int testament = localToTestamentBook(bookIndex, &bookInTestament); + if (testament >= 0) + { + sword::VerseKey verse; + verse.Testament(1+testament); + verse.Book(1+bookInTestament); + verse.Chapter(1+chapterIndex); + verse.Verse(1+verseIndex); + + m_module->setKey(&verse); + const char* text = m_module->RenderText(); + const char* preverse = m_module->getEntryAttributes()["Heading"]["Preverse"]["0"]; + outPassage->initVerse(bookIndex, 1+chapterIndex, 1+verseIndex, + QString::fromUtf8(preverse), + QString::fromUtf8(text)); + return true; + } + return false; +} + QString KwBibleModuleSword::renderText(const KwBibleModule::Key& key) { QString result; diff --git a/kworship/bible/KwBibleModuleSword.h b/kworship/bible/KwBibleModuleSword.h index d60d642..7a6482e 100644 --- a/kworship/bible/KwBibleModuleSword.h +++ b/kworship/bible/KwBibleModuleSword.h @@ -65,6 +65,9 @@ class KwBibleModuleSword : public KwBibleModule virtual int numVerses(int book, int chapter); // Reimplemented + virtual bool fillPassageVerse(int bookIndex, int chapterIndex, int verseIndex, KwBiblePassage* outPassage); + + // Reimplemented virtual QString renderText(const KwBibleModule::Key& key); protected: diff --git a/kworship/bible/KwBiblePassage.cpp b/kworship/bible/KwBiblePassage.cpp index fa000fc..4759c44 100644 --- a/kworship/bible/KwBiblePassage.cpp +++ b/kworship/bible/KwBiblePassage.cpp @@ -279,5 +279,31 @@ int KwBiblePassage::lastVerseNumber(int bookNumber, int chapterNumber) const /// Get the entire passaage rendered as HTML. QString KwBiblePassage::renderedText() { - return "TESTING"; + QString result; + Book* book = m_books; + for (int bookIndex = 0; bookIndex < m_numBooks; ++bookIndex) + { + Chapter* chapter = book->chapters; + for (int chapterIndex = 0; chapterIndex < book->numChapters; ++chapterIndex) + { + Verse* verse = chapter->verses; + for (int verseIndex = 0; verseIndex < chapter->numVerses; ++verseIndex) + { + if (!verse->headings.isEmpty()) + { + result += QString("

%1

").arg(verse->headings); + } + if (!verse->content.isEmpty()) + { + result += QString("%1").arg(chapter->firstVerse + verseIndex); + result += verse->content; + } + result += "
"; + ++verse; + } + ++chapter; + } + ++book; + } + return result; } -- 2.11.4.GIT