From a278a3efce54e3cc46171dcac71b9547b41c3cc1 Mon Sep 17 00:00:00 2001 From: James Hogan Date: Sun, 2 Nov 2008 01:50:11 +0000 Subject: [PATCH] Change interface to categorise bibles by language, and adapt SWORD bible manager to output required language data --- kworship/bible/KwBibleManagerSword.cpp | 25 +++++++++++-- kworship/bible/KwBibleManagerSword.h | 11 +++++- kworship/kworship.cpp | 68 ++++++++++++++++++++++++---------- kworship/kworship.h | 15 +++++--- 4 files changed, 88 insertions(+), 31 deletions(-) diff --git a/kworship/bible/KwBibleManagerSword.cpp b/kworship/bible/KwBibleManagerSword.cpp index 330417a..159db6a 100644 --- a/kworship/bible/KwBibleManagerSword.cpp +++ b/kworship/bible/KwBibleManagerSword.cpp @@ -40,6 +40,8 @@ KwBibleManagerSword::KwBibleManagerSword() : KwBibleManager() , m_manager(new sword::SWMgr(new sword::MarkupFilterMgr(sword::FMT_HTMLHREF))) , m_modules() +, m_languages() +, m_modulesByLanguage() { m_manager->setGlobalOption("Headings", "On"); @@ -52,7 +54,14 @@ KwBibleManagerSword::KwBibleManagerSword() sword::SWText* text = dynamic_cast(module); if (0 != text) { - m_modules[QLatin1String(modName)] = new KwBibleModuleSword(text); + QString name = QString::fromUtf8(modName); + m_modules[name] = new KwBibleModuleSword(text); + QString lang = QString::fromUtf8(module->Lang()); + if (-1 == m_languages.indexOf(lang)) + { + m_languages << lang; + } + m_modulesByLanguage[lang] << name; } } } @@ -83,7 +92,7 @@ bool KwBibleManagerSword::isRemote() const KwBibleModule* KwBibleManagerSword::module(const QString& name) { - QMap::const_iterator it = m_modules.constFind(name); + QHash::const_iterator it = m_modules.constFind(name); if (it != m_modules.constEnd()) { return *it; @@ -101,11 +110,19 @@ QStringList KwBibleManagerSword::moduleNames() QStringList KwBibleManagerSword::moduleNamesInLanguage(const QString& lang) { - return QStringList(); + QHash::const_iterator it = m_modulesByLanguage.constFind(lang); + if (it != m_modulesByLanguage.constEnd()) + { + return *it; + } + else + { + return QStringList(); + } } QStringList KwBibleManagerSword::languages() { - return QStringList(); + return m_languages; } diff --git a/kworship/bible/KwBibleManagerSword.h b/kworship/bible/KwBibleManagerSword.h index 55b3802..3de959e 100644 --- a/kworship/bible/KwBibleManagerSword.h +++ b/kworship/bible/KwBibleManagerSword.h @@ -28,6 +28,9 @@ #include "KwBibleManager.h" +#include +#include + namespace sword { class SWMgr; @@ -80,7 +83,13 @@ class KwBibleManagerSword : public KwBibleManager sword::SWMgr* m_manager; /// Modules managed by this manager. - QMap m_modules; + QHash m_modules; + + /// Languages. + QStringList m_languages; + + /// Modules by language. + QHash m_modulesByLanguage; }; #endif // _KwBibleManagerSword_h_ diff --git a/kworship/kworship.cpp b/kworship/kworship.cpp index 0d18e48..eff8e8a 100644 --- a/kworship/kworship.cpp +++ b/kworship/kworship.cpp @@ -381,11 +381,7 @@ kworship::kworship() else { mgr.toolBar = 0; - QStringList modules = manager->moduleNames(); - foreach (QString module, modules) - { - mgr.comboBibles->addItem(module, QVariant(module)); - } + fillBiblesList(&mgr); } layout->addWidget(mgr.comboBibles); @@ -1060,30 +1056,44 @@ void kworship::songdbEditSongBooks() // Bibles +void kworship::fillBiblesList(BibleManager* mgr) +{ + QStringList languages = mgr->manager->languages(); + mgr->comboBibles->clear(); + foreach (QString language, languages) + { + QStringList modules = mgr->manager->moduleNamesInLanguage(language); + if (!modules.isEmpty()) + { + mgr->comboBibles->addItem(language, QVariant(modules.first())); + foreach (QString module, modules) + { + mgr->comboBibles->addItem(" " + module, QVariant(module)); + } + } + } +} + void kworship::bibleConnect() { // Get the current bible manager int tab = m_bibleTabs->currentIndex(); Q_ASSERT(tab >= 0 && tab < m_bibles.size()); - BibleManager& mgr = m_bibles[tab]; + BibleManager* mgr = &m_bibles[tab]; // This will force the connection - QStringList modules = mgr.manager->moduleNames(); - mgr.comboBibles->clear(); - if (modules.isEmpty()) + fillBiblesList(mgr); + if (mgr->comboBibles->count() == 0) { KMessageBox::information(this, i18n("No bibles found")); } else { - mgr.comboBibles->setEnabled(true); - foreach (QString module, modules) - { - mgr.comboBibles->addItem(module, QVariant(module)); - } + mgr->comboBibles->setEnabled(true); } } +#include void kworship::bibleChanged() { // Get the current bible manager @@ -1094,8 +1104,14 @@ void kworship::bibleChanged() bool enabled = mgr.comboBibles->isEnabled(); // Is a bible selected? - QString bible = mgr.comboBibles->currentText(); - KwBibleModule* module = mgr.manager->module(bible); + int bibleInd = mgr.comboBibles->currentIndex(); + QString bible; + KwBibleModule* module = 0; + if (bibleInd >= 0) + { + QString bible = mgr.comboBibles->itemData(bibleInd).toString(); + module = mgr.manager->module(bible); + } // Update the list of books QString book = m_view->comboBibleBook->currentText(); @@ -1149,8 +1165,14 @@ void kworship::bibleBookChanged() BibleManager& mgr = m_bibles[tab]; // Is a bible selected? - QString bible = mgr.comboBibles->currentText(); - KwBibleModule* module = mgr.manager->module(bible); + int bibleInd = mgr.comboBibles->currentIndex(); + QString bible; + KwBibleModule* module = 0; + if (bibleInd >= 0) + { + QString bible = mgr.comboBibles->itemData(bibleInd).toString(); + module = mgr.manager->module(bible); + } if (0 != module) { // Is a book selected? @@ -1177,8 +1199,14 @@ void kworship::bibleChapterChanged() BibleManager& mgr = m_bibles[tab]; // Is a bible selected? - QString bible = mgr.comboBibles->currentText(); - KwBibleModule* module = mgr.manager->module(bible); + int bibleInd = mgr.comboBibles->currentIndex(); + QString bible; + KwBibleModule* module = 0; + if (bibleInd >= 0) + { + QString bible = mgr.comboBibles->itemData(bibleInd).toString(); + module = mgr.manager->module(bible); + } if (0 != module) { // Is a book selected? diff --git a/kworship/kworship.h b/kworship/kworship.h index cbd6f1d..eb1a155 100644 --- a/kworship/kworship.h +++ b/kworship/kworship.h @@ -146,6 +146,15 @@ private: // Presentations void setPresentation(UpPresentation* presentation, bool alreadyDestroyed = false); + // Bibles + struct BibleManager + { + KwBibleManager* manager; + QComboBox* comboBibles; + QToolBar* toolBar; + }; + void fillBiblesList(BibleManager* mgr); + private: Ui::prefs_base ui_prefs_base ; Ui::prefsPresentations_base ui_prefsPresentations_base ; @@ -169,12 +178,6 @@ private: KAction* m_editSongAction; KAction* m_editSongBooksAction; - struct BibleManager - { - KwBibleManager* manager; - QComboBox* comboBibles; - QToolBar* toolBar; - }; QTabWidget* m_bibleTabs; QList m_bibles; -- 2.11.4.GIT