From 35225693e0bf128686dab3ae12913b7aad214a68 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Tue, 23 Dec 2008 01:14:13 +0000 Subject: [PATCH] Right to leftness stored in bible passage and module, affects html rendering and is detected by bible gateway backend --- kworship/bible/KwBibleModule.cpp | 15 ++++++++++++++- kworship/bible/KwBibleModule.h | 9 +++++++++ kworship/bible/KwBibleModuleBibleGateway.cpp | 7 +++++++ kworship/bible/KwBiblePassage.cpp | 8 +++++++- kworship/bible/KwBiblePassage.h | 6 +++++- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/kworship/bible/KwBibleModule.cpp b/kworship/bible/KwBibleModule.cpp index 2783736..c7d66c6 100644 --- a/kworship/bible/KwBibleModule.cpp +++ b/kworship/bible/KwBibleModule.cpp @@ -35,6 +35,7 @@ /// Default constructor. KwBibleModule::KwBibleModule() : m_books() +, m_rightToLeft(false) { } @@ -231,6 +232,12 @@ KwBibleModule::Key KwBibleModule::createKey(const QString& bookStart, int chapte return key; } +/// Is the text right to left? +bool KwBibleModule::isRightToLeft() const +{ + return m_rightToLeft; +} + /// List the books in this module. const QStringList& KwBibleModule::books() { @@ -303,7 +310,7 @@ bool KwBibleModule::fillPassage(const Key& key, KwBiblePassage* outPassage) range.end.verse = range.start.verse; } - outPassage->setSource("MGR", name()); + outPassage->setSource("MGR", name(), m_rightToLeft); outPassage->initBooks(range.start.book, 1+range.end.book-range.start.book); for (int book = range.start.book; book <= range.end.book; ++book) { @@ -351,3 +358,9 @@ void KwBibleModule::setBooks(const QStringList& books) m_books = books; } +/// Set whether the module has text right-to-left. +void KwBibleModule::setRightToLeft(bool rightToLeft) +{ + m_rightToLeft = rightToLeft; +} + diff --git a/kworship/bible/KwBibleModule.h b/kworship/bible/KwBibleModule.h index 6404ec5..e4f5c99 100644 --- a/kworship/bible/KwBibleModule.h +++ b/kworship/bible/KwBibleModule.h @@ -104,6 +104,9 @@ class KwBibleModule /// Get the description of the module. virtual QString description() = 0; + /// Is the text right to left? + bool isRightToLeft() const; + /// List the books in this module. const QStringList& books(); @@ -144,6 +147,9 @@ class KwBibleModule /// Update the list of books. void setBooks(const QStringList& books); + /// Set whether the module has text right-to-left. + void setRightToLeft(bool rightToLeft); + private: /* @@ -153,6 +159,9 @@ class KwBibleModule /// List of book names. QStringList m_books; + /// Whether the module has text right to left. + bool m_rightToLeft; + }; #endif // _KwBibleModule_h_ diff --git a/kworship/bible/KwBibleModuleBibleGateway.cpp b/kworship/bible/KwBibleModuleBibleGateway.cpp index 2409c10..b0f32ab 100644 --- a/kworship/bible/KwBibleModuleBibleGateway.cpp +++ b/kworship/bible/KwBibleModuleBibleGateway.cpp @@ -73,6 +73,7 @@ KwBibleModuleBibleGateway::KwBibleModuleBibleGateway(int id) tableFound = true; // Each row except header is a book DOM::NodeList rows = tableElement.getElementsByTagName("tr"); + bool firstRow = true; for (unsigned int row = 0; row < rows.length(); ++row) { DOM::NodeList cells = DOM::Element(rows.item(row)).getElementsByTagName("td"); @@ -82,6 +83,12 @@ KwBibleModuleBibleGateway::KwBibleModuleBibleGateway(int id) m_bookList.push_back(Book()); Book* book = &m_bookList[m_bookList.size()-1]; book->name = DOM::HTMLElement(cells.item(0)).innerText().string(); + // Also check if text is right-to-left + if (firstRow) + { + setRightToLeft(DOM::HTMLElement(cells.item(0)).className().string().toLower().contains("rtl")); + firstRow = false; + } // Second cell is the chapter links DOM::NodeList chapterLinks = DOM::Element(cells.item(1)).getElementsByTagName("a"); for (unsigned int chapter = 0; chapter < chapterLinks.length(); ++chapter) diff --git a/kworship/bible/KwBiblePassage.cpp b/kworship/bible/KwBiblePassage.cpp index b83bc93..9d978d4 100644 --- a/kworship/bible/KwBiblePassage.cpp +++ b/kworship/bible/KwBiblePassage.cpp @@ -36,6 +36,7 @@ KwBiblePassage::KwBiblePassage() : m_managerId() , m_moduleId() , m_key() +, m_rightToLeft(false) , m_firstBook(0) , m_numBooks(0) , m_books(0) @@ -100,10 +101,11 @@ void KwBiblePassage::clearVerses(int bookNumber, int chapterNumber) } /// Set the source module. -void KwBiblePassage::setSource(const QString& managerId, const QString& moduleId) +void KwBiblePassage::setSource(const QString& managerId, const QString& moduleId, bool rightToLeft) { m_managerId = managerId; m_moduleId = moduleId; + m_rightToLeft = rightToLeft; } /// Initialise the books in the passage. @@ -280,6 +282,8 @@ int KwBiblePassage::lastVerseNumber(int bookNumber, int chapterNumber) const QString KwBiblePassage::renderedText() const { QString result; + result += QString("
").arg(m_rightToLeft ? "rtl" : "ltr"); + Book* book = m_books; for (int bookIndex = 0; bookIndex < m_numBooks; ++bookIndex) { @@ -304,5 +308,7 @@ QString KwBiblePassage::renderedText() const } ++book; } + + result += "
"; return result; } diff --git a/kworship/bible/KwBiblePassage.h b/kworship/bible/KwBiblePassage.h index 5b7e513..365272c 100644 --- a/kworship/bible/KwBiblePassage.h +++ b/kworship/bible/KwBiblePassage.h @@ -70,8 +70,9 @@ class KwBiblePassage /** Set the source module. * @param managerId ID of the bible manager. * @param moduleId ID of the bible module. + * @param rightToLeft Whether the text is right-to-left. */ - void setSource(const QString& managerId, const QString& moduleId); + void setSource(const QString& managerId, const QString& moduleId, bool rightToLeft); /** Initialise the books in the passage. * If books are already initialised they will be cleared first. @@ -220,6 +221,9 @@ class KwBiblePassage /// Original module key. KwBibleModule::Key m_key; + /// Whether the text is right-to-left. + bool m_rightToLeft; + /// The number of the first book. int m_firstBook; /// The number of books. -- 2.11.4.GIT