diff options
Diffstat (limited to 'src/backend/managers')
-rw-r--r-- | src/backend/managers/btstringmgr.cpp | 2 | ||||
-rw-r--r-- | src/backend/managers/btstringmgr.h | 2 | ||||
-rw-r--r-- | src/backend/managers/cdisplaytemplatemgr.cpp | 69 | ||||
-rw-r--r-- | src/backend/managers/cdisplaytemplatemgr.h | 119 | ||||
-rw-r--r-- | src/backend/managers/clanguagemgr.cpp | 28 | ||||
-rw-r--r-- | src/backend/managers/clanguagemgr.h | 57 | ||||
-rw-r--r-- | src/backend/managers/cswordbackend.cpp | 197 | ||||
-rw-r--r-- | src/backend/managers/cswordbackend.h | 173 | ||||
-rw-r--r-- | src/backend/managers/referencemanager.cpp | 46 | ||||
-rw-r--r-- | src/backend/managers/referencemanager.h | 17 |
10 files changed, 312 insertions, 398 deletions
diff --git a/src/backend/managers/btstringmgr.cpp b/src/backend/managers/btstringmgr.cpp index a2abc7f..ad1fb3e 100644 --- a/src/backend/managers/btstringmgr.cpp +++ b/src/backend/managers/btstringmgr.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/backend/managers/btstringmgr.h b/src/backend/managers/btstringmgr.h index 7f44df8..1cf7170 100644 --- a/src/backend/managers/btstringmgr.h +++ b/src/backend/managers/btstringmgr.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ diff --git a/src/backend/managers/cdisplaytemplatemgr.cpp b/src/backend/managers/cdisplaytemplatemgr.cpp index 11d2a59..b3def8c 100644 --- a/src/backend/managers/cdisplaytemplatemgr.cpp +++ b/src/backend/managers/cdisplaytemplatemgr.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -17,15 +17,38 @@ #include "backend/config/cbtconfig.h" #include "backend/drivers/cswordmoduleinfo.h" #include "backend/managers/clanguagemgr.h" -#include "util/cpointers.h" #include "util/directory.h" -CDisplayTemplateMgr::CDisplayTemplateMgr() { - loadTemplates(); -} +CDisplayTemplateMgr *CDisplayTemplateMgr::m_instance = 0; + +CDisplayTemplateMgr::CDisplayTemplateMgr(QString &errorMessage) { + Q_ASSERT(m_instance == 0); -CDisplayTemplateMgr::~CDisplayTemplateMgr() { + m_instance = this; + namespace DU = util::directory; + + QStringList filter("*.tmpl"); + + // Preload global display templates from disk: + QDir td = DU::getDisplayTemplatesDir(); + Q_FOREACH(QString file, td.entryList(filter, QDir::Files | QDir::Readable)) + loadTemplate(td.canonicalPath() + "/" + file); + + /* + Preload user display templates from disk, overriding any global templates + with the same file name: + */ + QDir utd = DU::getUserDisplayTemplatesDir(); + Q_FOREACH(QString file, utd.entryList(filter, QDir::Files | QDir::Readable)) + loadTemplate(utd.canonicalPath() + "/" + file); + + if (m_templateMap.contains(defaultTemplate())) { + errorMessage = QString::null; + } else { + errorMessage = QObject::tr("Default template \"%1\" not found!") + .arg(defaultTemplate()); + } } const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QString& content, Settings& settings ) { @@ -70,9 +93,9 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr qDebug() << "There were more than 1 module, create headers"; QString header; - QList<CSwordModuleInfo*>::iterator end_it = settings.modules.end(); + QList<const CSwordModuleInfo*>::iterator end_it = settings.modules.end(); - for (QList<CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) { + for (QList<const CSwordModuleInfo*>::iterator it(settings.modules.begin()); it != end_it; ++it) { header.append("<th style=\"width:") .append(QString::number(int( 100.0 / (float)moduleCount ))) .append("%;\">") @@ -88,7 +111,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr } QString langCSS; - CLanguageMgr::LangMap langMap = CPointers::languageMgr()->availableLanguages(); + CLanguageMgr::LangMap langMap = CLanguageMgr::instance()->availableLanguages(); qDebug() << "langMap length:" << langMap.count(); qDebug() << "loop through langMap"; @@ -118,7 +141,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr //at first append the font standard settings for all languages without configured font // Create a dummy language (the langmap may be empty) - CLanguageMgr::Language lang_v(QString("en"), QString("English"), QString()); + CLanguageMgr::Language lang_v(QString("en"), QString("English"), QString::null); CLanguageMgr::Language* lang = &lang_v; if (lang && !lang->abbrev().isEmpty()/*&& lang->isValid()*/) { @@ -132,7 +155,7 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr ); } -// qWarning("Outputing unformated text"); +// qWarning("Outputing unformated text"); const QString t = QString(m_templateMap[ templateName ]) //don't change the map's content directly, use a copy .replace("#TITLE#", settings.title) .replace("#LANG_ABBREV#", settings.langAbbrev.isEmpty() ? QString("en") : settings.langAbbrev) @@ -144,25 +167,13 @@ const QString CDisplayTemplateMgr::fillTemplate( const QString& name, const QStr return t; } -void CDisplayTemplateMgr::loadTemplates() { - namespace DU = util::directory; - - QStringList files; - foreach (QString file, DU::getDisplayTemplatesDir().entryList(QStringList("*.tmpl"))) { - files += DU::getDisplayTemplatesDir().canonicalPath() + "/" + file; - } - foreach (QString file, DU::getUserDisplayTemplatesDir().entryList(QStringList("*.tmpl"))) { - files += DU::getUserDisplayTemplatesDir().canonicalPath() + "/" + file; - } - - foreach (QString file, files) { - QFile f(file); - if (f.exists() && f.open( QIODevice::ReadOnly )) { - QString fileContent = QTextStream( &f ).readAll(); +void CDisplayTemplateMgr::loadTemplate(const QString &filename) { + QFile f(filename); + if (f.open(QIODevice::ReadOnly)) { + QString fileContent = QTextStream(&f).readAll(); - if (!fileContent.isEmpty()) { - m_templateMap[ QFileInfo(file).fileName() ] = fileContent; - } + if (!fileContent.isEmpty()) { + m_templateMap[QFileInfo(f).fileName()] = fileContent; } } } diff --git a/src/backend/managers/cdisplaytemplatemgr.h b/src/backend/managers/cdisplaytemplatemgr.h index 16725a5..9b96e8b 100644 --- a/src/backend/managers/cdisplaytemplatemgr.h +++ b/src/backend/managers/cdisplaytemplatemgr.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -18,71 +18,82 @@ class CSwordModuleInfo; /** - * Manages the display templates used in the filters and display classes. - * @author The BibleTime team + Manages the display templates used in the filters and display classes. + \note This is a singleton. */ class CDisplayTemplateMgr { - public: - /** Settings which are used to fill the content into the template. + public: /* Types: */ + /** + Settings which are used to fill the content into the template. */ - struct Settings { - /** Constructor. Constructs the new settings object. The default values are empty. - */ - Settings() { - title = QString::null; - langAbbrev = QString::null; - pageCSS_ID = QString::null; - pageDirection = QString("ltr"); - }; - - QList<CSwordModuleInfo*> modules; /**< the list of modules */ - QString title; /**< the title which is used for the new processed HTML page */ - QString langAbbrev; /**< the language for the HTML page. */ - QString pageDirection; /**< the language for the HTML page. */ - QString pageCSS_ID; /**< the CSS ID which is used in the content part of the page */ + Settings() : pageDirection("ltr") {} + + /** The list of modules */ + QList<const CSwordModuleInfo*> modules; + + /** The title which is used for the new processed HTML page */ + QString title; + + /** The language for the HTML page. */ + QString langAbbrev; + + /** The language direction for the HTML page. */ + QString pageDirection; + + /** The CSS ID which is used in the content part of the page */ + QString pageCSS_ID; }; - /** Available templates. - * @return The list of templates, which are available. + public: /* Methods: */ + + /** + \param[out] errorMessage Set to error string on error, otherwise set + to QString::null. */ - inline const QStringList availableTemplates(); - /** Fill template. Fill rendered content into the template given by the name. - * @param name The name of the template - * @param content The content which should be filled into the template - * @param settings The settings which are used to process the templating process - * @return The full HTML template HTML code including the CSS data. + explicit CDisplayTemplateMgr(QString &errorMessage); + + /** + \returns the list of available templates. */ - const QString fillTemplate( const QString& name, const QString& content, Settings& settings); - /** Default template. - * @return The i18n'ed name of the default template + inline const QStringList availableTemplates() const { + return m_templateMap.keys(); + } + + /** + \brief Fills the template. + + Fills rendered content into the template given by the name. + + \param name The name of the template to fill. + \param content The content which should be filled into the template. + \param settings The settings which are used to process the templating + process. + + \returns The full HTML template HTML code including the CSS data. */ - inline static const QString defaultTemplate(); - - protected: - friend class CPointers; - /** Display template manager constructor. Protected to just allow CPointers to create objects. */ - CDisplayTemplateMgr(); - /** Destructor. */ - ~CDisplayTemplateMgr(); - /** Does the actual work of loading templates from disk */ - void loadTemplates(); - - private: - QMap<QString, QString> m_templateMap; -}; + const QString fillTemplate( const QString& name, const QString& content, Settings& settings); -inline const QString CDisplayTemplateMgr::defaultTemplate() { - return QString("Blue.tmpl"); -} + /** + \returns the name of the default template. + */ + inline static const char *defaultTemplate() { return "Blue.tmpl"; } -/** - * CDisplayTemplateMgr::availableTemplates() - */ -inline const QStringList CDisplayTemplateMgr::availableTemplates() { - return m_templateMap.keys(); -} + /** + \returns The singleton instance of the instance of this class. + */ + static inline CDisplayTemplateMgr *instance() { + Q_ASSERT(m_instance != 0); + return m_instance; + }; + private: /* Methods: */ + /** Preloads a single template from disk: */ + void loadTemplate(const QString &filename); + private: /* Fields: */ + QMap<QString, QString> m_templateMap; + static CDisplayTemplateMgr *m_instance; +}; #endif diff --git a/src/backend/managers/clanguagemgr.cpp b/src/backend/managers/clanguagemgr.cpp index 5c44405..a8d4e1f 100644 --- a/src/backend/managers/clanguagemgr.cpp +++ b/src/backend/managers/clanguagemgr.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -11,7 +11,6 @@ #include "backend/drivers/cswordmoduleinfo.h" #include "backend/managers/cswordbackend.h" -#include "util/cpointers.h" CLanguageMgr::Language::Language() {} @@ -37,6 +36,22 @@ CLanguageMgr::Language::~Language() { /****************************************************/ /******************** CLanguageMgr ******************/ /****************************************************/ + +CLanguageMgr *CLanguageMgr::m_instance = 0; + +void CLanguageMgr::destroyInstance() { + delete m_instance; + m_instance = 0; +} + +CLanguageMgr *CLanguageMgr::instance() { + if (m_instance == 0) { + m_instance = new CLanguageMgr(); + } + + return m_instance; +} + CLanguageMgr::CLanguageMgr() : m_langMap() { m_availableModulesCache.moduleCount = 0; init(); @@ -50,7 +65,7 @@ CLanguageMgr::~CLanguageMgr() { } const CLanguageMgr::LangMap& CLanguageMgr::availableLanguages() { - QList<CSwordModuleInfo*> mods = CPointers::backend()->moduleList(); + QList<CSwordModuleInfo*> mods = CSwordBackend::instance()->moduleList(); if ( m_availableModulesCache.moduleCount != (unsigned int)mods.count() ) { //we have to refill the cached map m_availableModulesCache.availableLanguages.clear(); @@ -98,13 +113,6 @@ const CLanguageMgr::Language* CLanguageMgr::languageForAbbrev( const QString& ab return newLang; } -const CLanguageMgr::Language* CLanguageMgr::languageForName( const QString& name ) const { - foreach ( const Language* lang, m_langList ) { - if (lang->name() == name) return lang; - } - return &m_defaultLanguage;//invalid language -} - const CLanguageMgr::Language* CLanguageMgr::languageForTranslatedName( const QString& name ) const { foreach ( const Language* lang, m_langList ) { if (lang->translatedName() == name) return lang; diff --git a/src/backend/managers/clanguagemgr.h b/src/backend/managers/clanguagemgr.h index de716c0..cbe70e9 100644 --- a/src/backend/managers/clanguagemgr.h +++ b/src/backend/managers/clanguagemgr.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,9 +16,10 @@ #include <QStringList> -/** Manages the languages of BibleTime and provides functions to work with them. - * @author The BibleTime team - */ +/** + \brief Manages the languages and provides functions to work with them. + \note This is a singleton. +*/ class CLanguageMgr { public: @@ -27,21 +28,21 @@ class CLanguageMgr { */ class Language { public: - /** Default constructor of a language object. - * Uses the abbreviation parameter to lookup the - * language name and to be able to return the name, flag etc. - * Possible values for abbrev are de, en, fr, it etc. + /** + Uses the abbreviation parameter to lookup the language name + and to be able to return the name, flag etc. Possible values + for abbrev are de, en, fr, it etc. */ Language(); - /** Copy constructor. - */ - Language(const Language&); - /** Constructor which takes all necessary data. - */ - Language(const QString& abbrev, const QString& englishName, const QString& translatedName, const QStringList& altAbbrevs = QStringList()); - /** Destructor. - */ + + Language(const Language ©); + + Language(const QString &abbrev, const QString &englishName, + const QString &translatedName, + const QStringList &altAbbrevs = QStringList()); + ~Language(); + /** Returns the abbreviation. * @return The abbreviation of the chosen language. */ @@ -88,12 +89,17 @@ class CLanguageMgr { typedef QHash<QString, const Language*> LangMap; typedef QHash<QString, const Language*>::const_iterator LangMapIterator; - /** Constructor. - */ + + /** Returns the singleton instance, creating it if one does not exist. */ + static CLanguageMgr *instance(); + + /** Destroys the singleton instance, if one exists. */ + static void destroyInstance(); + CLanguageMgr(); - /** Destructor - */ + virtual ~CLanguageMgr(); + /** * Returns the standard languages available as standard. Does nothing for Sword. * @return A LangMap map which contains all known languages @@ -111,11 +117,7 @@ class CLanguageMgr { * @return Pointer to a language for the given string abbreviation. */ const CLanguageMgr::Language* languageForAbbrev( const QString& abbrev ) const; - /** Language for english name. - * @param abbrev The english language name. - * @return Pointer to a language for the given name - */ - const CLanguageMgr::Language* languageForName( const QString& language ) const; + /** Language for translated language name. * @param abbrev The translated language name * @return Pointer to a language for the given translated language name @@ -142,8 +144,9 @@ class CLanguageMgr { struct ModuleCache { unsigned int moduleCount; LangMap availableLanguages; - } - m_availableModulesCache; + } m_availableModulesCache; + + static CLanguageMgr *m_instance; }; #endif diff --git a/src/backend/managers/cswordbackend.cpp b/src/backend/managers/cswordbackend.cpp index 4596a61..b5c109f 100644 --- a/src/backend/managers/cswordbackend.cpp +++ b/src/backend/managers/cswordbackend.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -20,16 +20,9 @@ #include "backend/drivers/cswordbookmoduleinfo.h" #include "backend/drivers/cswordcommentarymoduleinfo.h" #include "backend/drivers/cswordlexiconmoduleinfo.h" -#include "backend/filters/bt_gbfhtml.h" -#include "backend/filters/bt_osishtml.h" -#include "backend/filters/bt_teihtml.h" -#include "backend/filters/bt_plainhtml.h" -#include "backend/filters/bt_thmlhtml.h" -#include "backend/filters/bt_thmlplain.h" +#include "backend/filters/thmltoplain.h" #include "backend/filters/osismorphsegmentation.h" -#include "backend/rendering/cbookdisplay.h" -#include "backend/rendering/cchapterdisplay.h" -#include "backend/rendering/centrydisplay.h" +#include "btglobal.h" #include "util/directory.h" // Sword includes: @@ -42,52 +35,25 @@ #include <utilstr.h> -using namespace Filters; using namespace Rendering; -CSwordBackend::CSwordBackend() - : sword::SWMgr(0, 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), true), - m_dataModel(this) { - m_filters.gbf = new BT_GBFHTML(); - m_filters.plain = new BT_PLAINHTML(); - m_filters.thml = new BT_ThMLHTML(); - m_filters.osis = new BT_OSISHTML(); - m_filters.tei = new BT_TEIHTML(); - - m_displays.entry = new CEntryDisplay(); - m_displays.chapter = new CChapterDisplay(); - m_displays.book = new CBookDisplay(); +CSwordBackend *CSwordBackend::m_instance = 0; +CSwordBackend::CSwordBackend() + : sword::SWMgr(0, 0, false, + new sword::EncodingFilterMgr(sword::ENC_UTF8), true), + m_dataModel(this) +{ filterInit(); } CSwordBackend::CSwordBackend(const QString& path, const bool augmentHome) : sword::SWMgr(!path.isEmpty() ? path.toLocal8Bit().constData() : 0, false, new sword::EncodingFilterMgr( sword::ENC_UTF8 ), false, augmentHome) { // don't allow module renaming, because we load from a path - m_filters.gbf = new BT_GBFHTML(); - m_filters.plain = new BT_PLAINHTML(); - m_filters.thml = new BT_ThMLHTML(); - m_filters.osis = new BT_OSISHTML(); - m_filters.tei = new BT_TEIHTML(); - - m_displays.entry = new CEntryDisplay(); - m_displays.chapter = new CChapterDisplay(); - m_displays.book = new CBookDisplay(); - filterInit(); } CSwordBackend::~CSwordBackend() { shutdownModules(); - - delete m_filters.gbf; - delete m_filters.plain; - delete m_filters.thml; - delete m_filters.osis; - delete m_filters.tei; - - delete m_displays.book; - delete m_displays.chapter; - delete m_displays.entry; } void CSwordBackend::filterInit() { @@ -97,7 +63,7 @@ void CSwordBackend::filterInit() { optionFilters.erase("OSISMorphSegmentation"); delete filter; } - sword::SWOptionFilter* tmpFilter = new OSISMorphSegmentation(); + sword::SWOptionFilter *tmpFilter = new Filters::OSISMorphSegmentation(); optionFilters.insert(sword::OptionFilterMap::value_type("OSISMorphSegmentation", tmpFilter)); cleanupFilters.push_back(tmpFilter); @@ -105,7 +71,7 @@ void CSwordBackend::filterInit() { //remove this hack as soon as Sword is fixed cleanupFilters.remove(thmlplain); delete thmlplain; - thmlplain = new BT_ThMLPlain(); + thmlplain = new Filters::ThmlToPlain(); cleanupFilters.push_back(thmlplain); } @@ -125,10 +91,23 @@ QList<CSwordModuleInfo*> CSwordBackend::takeModulesFromList(QStringList names) { return list; } -QList<CSwordModuleInfo*> CSwordBackend::getPointerList(QStringList names) { +QList<CSwordModuleInfo*> CSwordBackend::getPointerList(const QStringList &names) { QList<CSwordModuleInfo*> list; - foreach(QString name, names) { - CSwordModuleInfo* mInfo = findModuleByName(name); + Q_FOREACH (const QString &name, names) { + CSwordModuleInfo *mInfo = findModuleByName(name); + if (mInfo) { + list.append(mInfo); + } + } + return list; +} + +QList<const CSwordModuleInfo*> CSwordBackend::getConstPointerList( + const QStringList &names) +{ + QList<const CSwordModuleInfo*> list; + Q_FOREACH (const QString &name, names) { + const CSwordModuleInfo *mInfo = findModuleByName(name); if (mInfo) { list.append(mInfo); } @@ -154,19 +133,19 @@ CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) { if (!strcmp(curMod->Type(), "Biblical Texts")) { newModule = new CSwordBibleModuleInfo(curMod, this); - newModule->module()->Disp(m_displays.chapter); + newModule->module()->Disp(&m_chapterDisplay); } else if (!strcmp(curMod->Type(), "Commentaries")) { newModule = new CSwordCommentaryModuleInfo(curMod, this); - newModule->module()->Disp(m_displays.entry); + newModule->module()->Disp(&m_entryDisplay); } else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) { newModule = new CSwordLexiconModuleInfo(curMod, this); - newModule->module()->Disp(m_displays.entry); + newModule->module()->Disp(&m_entryDisplay); } else if (!strcmp(curMod->Type(), "Generic Books")) { newModule = new CSwordBookModuleInfo(curMod, this); - newModule->module()->Disp(m_displays.book); + newModule->module()->Disp(&m_bookDisplay); } if (newModule) { @@ -181,8 +160,7 @@ CSwordBackend::LoadError CSwordBackend::initModules(SetupChangedReason reason) { } } - Q_FOREACH(CSwordModuleInfo* mod, m_dataModel.modules()) { - m_moduleDescriptionMap.insert( mod->config(CSwordModuleInfo::Description), mod->name() ); + Q_FOREACH(CSwordModuleInfo* mod, m_dataModel.moduleList()) { //unlock modules if keys are present if ( mod->isEncrypted() ) { const QString unlockKey = CBTConfig::getModuleEncryptionKey( mod->name() ); @@ -206,29 +184,29 @@ void CSwordBackend::AddRenderFilters(sword::SWModule *module, sword::ConfigEntMa moduleDriver = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (sword::SWBuf) ""; if (sourceformat == "OSIS") { - module->AddRenderFilter(m_filters.osis); + module->AddRenderFilter(&m_osisFilter); noDriver = false; } else if (sourceformat == "ThML") { - module->AddRenderFilter(m_filters.thml); + module->AddRenderFilter(&m_thmlFilter); noDriver = false; } else if (sourceformat == "TEI") { - module->AddRenderFilter(m_filters.tei); + module->AddRenderFilter(&m_teiFilter); noDriver = false; } else if (sourceformat == "GBF") { - module->AddRenderFilter(m_filters.gbf); + module->AddRenderFilter(&m_gbfFilter); noDriver = false; } else if (sourceformat == "PLAIN") { - module->AddRenderFilter(m_filters.plain); + module->AddRenderFilter(&m_plainFilter); noDriver = false; } if (noDriver) { //no driver found if ( (moduleDriver == "RawCom") || (moduleDriver == "RawLD") ) { - module->AddRenderFilter(m_filters.plain); + module->AddRenderFilter(&m_plainFilter); noDriver = false; } } @@ -284,7 +262,7 @@ void CSwordBackend::setOption( const CSwordModuleInfo::FilterTypes type, const i setGlobalOption(optionName(type).toUtf8().constData(), value.c_str()); } -void CSwordBackend::setFilterOptions( const CSwordBackend::FilterOptions options) { +void CSwordBackend::setFilterOptions(const FilterOptions &options) { setOption( CSwordModuleInfo::footnotes, options.footnotes ); setOption( CSwordModuleInfo::strongNumbers, options.strongNumbers ); setOption( CSwordModuleInfo::headings, options.headings ); @@ -302,93 +280,27 @@ void CSwordBackend::setFilterOptions( const CSwordBackend::FilterOptions options /** This function searches for a module with the specified description */ CSwordModuleInfo* CSwordBackend::findModuleByDescription(const QString& description) { - Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) { + Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if (mod->config(CSwordModuleInfo::Description) == description) return mod; } return 0; } -/** This function searches for a module with the specified description */ -const QString CSwordBackend::findModuleNameByDescription(const QString& description) { - if (m_moduleDescriptionMap.contains(description)) { - return m_moduleDescriptionMap[description]; - } - return QString::null; -} - /** This function searches for a module with the specified name */ CSwordModuleInfo* CSwordBackend::findModuleByName(const QString& name) { - Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) { + Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if (mod->name() == name) return mod; } return 0; } CSwordModuleInfo* CSwordBackend::findSwordModuleByPointer(const sword::SWModule* const swmodule) { - Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) { + Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if (mod->module() == swmodule ) return mod; } return 0; } -CSwordModuleInfo* CSwordBackend::findModuleByPointer(const CSwordModuleInfo* const module) { - Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) { - if (mod == module) return mod; - } - return 0; -} - -/** Returns our local config object to store the cipher keys etc. locally for each user. The values of the config are merged with the global config. */ -bool CSwordBackend::moduleConfig(const QString& module, sword::SWConfig& moduleConfig) { - - sword::SectionMap::iterator section; - QDir dir(QString::fromUtf8(configPath)); - bool foundConfig = false; - - QFileInfoList list = dir.entryInfoList(); - if (dir.isReadable()) { - for (int i = 0; i < list.size(); ++i) { - QFileInfo fileInfo = list.at(i); - - moduleConfig = sword::SWConfig( fileInfo.absoluteFilePath().toLocal8Bit().constData() ); - section = moduleConfig.Sections.find( module.toLocal8Bit().constData() ); - foundConfig = ( section != moduleConfig.Sections.end() ); - } - } - else { //try to read mods.conf - moduleConfig = sword::SWConfig("");//global config - section = config->Sections.find( module.toLocal8Bit().constData() ); - foundConfig = ( section != config->Sections.end() ); - - sword::ConfigEntMap::iterator entry; - - if (foundConfig) { //copy module section - - for (entry = section->second.begin(); entry != section->second.end(); entry++) { - moduleConfig.Sections[section->first].insert(sword::ConfigEntMap::value_type(entry->first, entry->second)); - } - } - } - - if (!foundConfig && configType != 2) { //search in $HOME/.sword/ - - QString myPath = util::directory::getUserHomeSwordModsDir().absolutePath(); - dir.setPath(myPath); - - QFileInfoList list = dir.entryInfoList(); - if (dir.isReadable()) { - for (int i = 0; i < list.size(); ++i) { - QFileInfo fileInfo = list.at(i); - moduleConfig = sword::SWConfig( fileInfo.absoluteFilePath().toLocal8Bit().constData() ); - section = moduleConfig.Sections.find( module.toLocal8Bit().constData() ); - foundConfig = ( section != moduleConfig.Sections.end() ); - } - } - } - - return foundConfig; -} - /** Returns the text used for the option given as parameter. */ const QString CSwordBackend::optionName( const CSwordModuleInfo::FilterTypes option ) { switch (option) { @@ -490,7 +402,7 @@ const QString CSwordBackend::booknameLanguage( const QString& language ) { //use what sword returns, language may be different QString newLocaleName( sword::LocaleMgr::getSystemLocaleMgr()->getDefaultLocaleName() ); - Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.modules()) { + Q_FOREACH (CSwordModuleInfo *mod, m_dataModel.moduleList()) { if ( (mod->type() == CSwordModuleInfo::Bible) || (mod->type() == CSwordModuleInfo::Commentary) ) { //Create a new key, it will get the default bookname language ((sword::VerseKey*)(mod->module()->getKey()))->setLocale( newLocaleName.toUtf8().constData() ); @@ -609,3 +521,26 @@ QStringList CSwordBackend::swordDirList() const { return swordDirSet.values(); } + +void CSwordBackend::deleteOrphanedIndices() { + QDir dir(CSwordModuleInfo::getGlobalBaseIndexLocation()); + dir.setFilter(QDir::Dirs); + CSwordModuleInfo* module; + + for (unsigned int i = 0; i < dir.count(); i++) { + if (dir[i] != "." && dir[i] != "..") { + if ( (module = this->findModuleByName(dir[i])) ) { //mod exists + if (!module->hasIndex()) { //index files found, but wrong version etc. + qDebug() << "deleting outdated index for module" << dir[i]; + CSwordModuleInfo::deleteIndexForModule( dir[i] ); + } + } + else { //no module exists + if (CBTConfig::get( CBTConfig::autoDeleteOrphanedIndices ) ) { + qDebug() << "deleting orphaned index in directory" << dir[i]; + CSwordModuleInfo::deleteIndexForModule( dir[i] ); + } + } + } + } +} diff --git a/src/backend/managers/cswordbackend.h b/src/backend/managers/cswordbackend.h index c8b4f77..68be102 100644 --- a/src/backend/managers/cswordbackend.h +++ b/src/backend/managers/cswordbackend.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -16,6 +16,14 @@ #include <QStringList> #include "backend/drivers/cswordmoduleinfo.h" #include "backend/bookshelfmodel/btbookshelfmodel.h" +#include "backend/filters/gbftohtml.h" +#include "backend/filters/osistohtml.h" +#include "backend/filters/plaintohtml.h" +#include "backend/filters/teitohtml.h" +#include "backend/filters/thmltohtml.h" +#include "backend/rendering/cbookdisplay.h" +#include "backend/rendering/cchapterdisplay.h" +#include "backend/rendering/centrydisplay.h" // Sword includes: #include <swmgr.h> @@ -25,20 +33,17 @@ #include <localemgr.h> #include <utilstr.h> -namespace Rendering { -class CEntryDisplay; -class CChapterDisplay; -class CBookDisplay; -} +/** + \brief The backend layer main class, a backend implementation of Sword. + + This is the implementation of CBackend for Sword. It's additionally derived + from SWMgr to provide functions of Sword. -/** The backend layer main class. - * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr - * to provide functions of Sword. - * - * @short The backend implementation of Sword - * @author The BibleTime team - * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $ - */ + \note Mostly, only one instance of this class is used. This instance is + created by BibleTime::initBackends() and is destroyed by + BibleTimeApp::~BibleTimeApp(). Only when \ref BackendNotSingleton + "managing modules" separate backends are created. +*/ class CSwordBackend : public QObject, public sword::SWMgr { Q_OBJECT public: @@ -52,32 +57,6 @@ class CSwordBackend : public QObject, public sword::SWMgr { OtherChange = 16 }; - /** Filter options. Filter options to - * control the text display of modules. Uses int and not bool because not all - * options have just two toggle values. - */ - struct FilterOptions { - int footnotes; /**< 0 for disabled, 1 for enabled */ - int strongNumbers; /**< 0 for disabled, 1 for enabled */ - int headings; /**< 0 for disabled, 1 for enabled */ - int morphTags; /**< 0 for disabled, 1 for enabled */ - int lemmas; /**< 0 for disabled, 1 for enabled */ - int hebrewPoints; /**< 0 for disabled, 1 for enabled */ - int hebrewCantillation; /**< 0 for disabled, 1 for enabled */ - int greekAccents; /**< 0 for disabled, 1 for enabled */ - int textualVariants; /**< Number n to enabled the n-th variant */ - int redLetterWords; /**< 0 for disabled, 1 for enabled */ - int scriptureReferences; /**< 0 for disabled, 1 for enabled */ - int morphSegmentation; /**< 0 for disabled, 1 for enabled */ - }; - - /** Control the display of a text. - */ - struct DisplayOptions { - int lineBreaks; - int verseNumbers; - }; - /** The error codes which may be returned by the @ref Load() call. */ enum LoadError { // the values exist to cast from the char return of SWMgr::Load @@ -86,12 +65,6 @@ class CSwordBackend : public QObject, public sword::SWMgr { NoModules = 1 }; /** - * The constructor of the Sword backend. - * It creates the SWModule objects using SWMgr's methods, it adds the necessary - * filters for the module format. - */ - CSwordBackend(); - /** * The constructor of the Sword backend. This is actually used nowhere. * Notice that using augmentHome=false can mess up the system because it is true elsewhere. * @param path The path which is used to load modules @@ -104,6 +77,19 @@ class CSwordBackend : public QObject, public sword::SWMgr { */ ~CSwordBackend(); + /** Creates and returns the instance. */ + static inline CSwordBackend *createInstance() { + Q_ASSERT(m_instance == 0); + m_instance = new CSwordBackend(); + return m_instance; + } + + /** Returns the singleton instance, creating it if one does not exist. */ + static inline CSwordBackend *instance() { return m_instance; } + + /** Destroys the singleton instance, if one exists. */ + static void destroyInstance() { delete m_instance; } + /** * This function returns the list of available modules managed by this * backend. You have to call initModules() first; This method is @@ -134,8 +120,8 @@ class CSwordBackend : public QObject, public sword::SWMgr { * @param enable If this is true the option will be enabled, otherwise it will be disabled. */ void setOption( const CSwordModuleInfo::FilterTypes type, const int state ); - /** */ - void setFilterOptions( const CSwordBackend::FilterOptions options ); + + void setFilterOptions(const FilterOptions &options); /** * Sets the language for the international booknames of Sword. * @param langName The abbreviation string which should be used for the Sword backend @@ -147,12 +133,7 @@ class CSwordBackend : public QObject, public sword::SWMgr { * @return pointer to the desired module; null if no module has the specified description */ CSwordModuleInfo* findModuleByDescription(const QString& description); - /** - * This function searches for a module with the specified description - * @param description The description of the desired module - * @return pointer to the desired module; null if no module has the specified description - */ - const QString findModuleNameByDescription(const QString& description); + /** * This function searches for a module with the specified name * @param name The name of the desired module @@ -165,21 +146,12 @@ class CSwordBackend : public QObject, public sword::SWMgr { * @return pointer to the desired module; null if no module has the specified name */ CSwordModuleInfo* findSwordModuleByPointer(const sword::SWModule* const swmodule); - /** - * This function searches for a module which is the same as the passed module. - * @param module The module which should be used for searching the new one. May be child of a different backend. - * @return Pointer to the desired module; null if no module has the specified name - */ - CSwordModuleInfo* findModuleByPointer(const CSwordModuleInfo* const module); + /** * @return Our global config object which contains the configs of all modules merged together. */ inline sword::SWConfig* getConfig() const; - /** - * Tries to find the config object for the module. The second paramter will be the found config. - * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state. - */ - bool moduleConfig(const QString& module, sword::SWConfig& moduleConfig ); + /** * Returns the text used for the option given as parameter. * @param The paramter enum @@ -195,11 +167,7 @@ class CSwordBackend : public QObject, public sword::SWMgr { * @param The translated option name */ static const QString translatedOptionName(const CSwordModuleInfo::FilterTypes option ); - /** - * Returns the version of the Sword library. - * @return The version used by this backend - */ - inline const sword::SWVersion Version(); + /** * Reload all Sword modules. */ @@ -212,22 +180,39 @@ class CSwordBackend : public QObject, public sword::SWMgr { QList<CSwordModuleInfo*> takeModulesFromList(QStringList names); /** - * Returns a list of pointers to modules, created from a list of module names. + \returns a list of pointers to modules, created from a list of module + names. + */ + QList<CSwordModuleInfo*> getPointerList(const QStringList &names); + + /** + \returns a list of pointers to const modules, created from a list of + module names. */ - QList<CSwordModuleInfo*> getPointerList(QStringList names); + QList<const CSwordModuleInfo*> getConstPointerList(const QStringList &names); /** Sword prefix list. * @return A list of all known Sword prefix dirs */ QStringList swordDirList() const; + /** + * delete all orphaned indexes (no module present) if autoDeleteOrphanedIndices is true + * delete all indices of modules where hasIndex() returns false (because of wrong index version etc.) + */ + void deleteOrphanedIndices(); signals: void sigSwordSetupChanged(CSwordBackend::SetupChangedReason reason); protected: /** - * Adds a render filter to the module. - * This is used to apply our own render filters to our modules instead of the sword filters + Creates the SWModule objects using SWMgr's methods, it adds the + necessary filters for the module format. + */ + CSwordBackend(); + + /** + * Reimplemented from sword::SWMgr. */ void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap §ion); /** @@ -239,32 +224,27 @@ class CSwordBackend : public QObject, public sword::SWMgr { QString getPrivateSwordConfigPath() const; QString getPrivateSwordConfigFile() const; - private: - // Filters - struct Filters { - sword::SWFilter* gbf; - sword::SWFilter* plain; - sword::SWFilter* thml; - sword::SWFilter* osis; - sword::SWFilter* tei; - } m_filters; - - struct Displays { - Rendering::CChapterDisplay* chapter; - Rendering::CEntryDisplay* entry; - Rendering::CBookDisplay* book; - } m_displays; + private: /* Fields: */ + // Filters: + Filters::GbfToHtml m_gbfFilter; + Filters::OsisToHtml m_osisFilter; + Filters::PlainToHtml m_plainFilter; + Filters::TeiToHtml m_teiFilter; + Filters::ThmlToHtml m_thmlFilter; + + // Displays: + Rendering::CChapterDisplay m_chapterDisplay; + Rendering::CEntryDisplay m_entryDisplay; + Rendering::CBookDisplay m_bookDisplay; BtBookshelfModel m_dataModel; - QMap<QString, QString> m_moduleDescriptionMap; -}; -Q_DECLARE_METATYPE(CSwordBackend::FilterOptions) -Q_DECLARE_METATYPE(CSwordBackend::DisplayOptions) + static CSwordBackend *m_instance; +}; /**Returns The list of modules managed by this backend*/ inline const QList<CSwordModuleInfo*> &CSwordBackend::moduleList() const { - return m_dataModel.modules(); + return m_dataModel.moduleList(); } inline BtBookshelfModel *CSwordBackend::model() { @@ -276,9 +256,4 @@ inline sword::SWConfig* CSwordBackend::getConfig() const { return config; } -/** Returns the version of the Sword library. */ -inline const sword::SWVersion CSwordBackend::Version() { - return sword::SWVersion::currentVersion; -} - #endif diff --git a/src/backend/managers/referencemanager.cpp b/src/backend/managers/referencemanager.cpp index 4fc5e53..de41af2 100644 --- a/src/backend/managers/referencemanager.cpp +++ b/src/backend/managers/referencemanager.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -10,12 +10,10 @@ #include "backend/managers/referencemanager.h" #include <algorithm> - #include <QRegExp> #include <QDebug> #include "backend/config/cbtconfig.h" #include "backend/keys/cswordversekey.h" -#include "util/cpointers.h" /** Returns a hyperlink used to be imbedded in the display windows. At the moment the format is sword://module/key */ @@ -87,15 +85,15 @@ const QString ReferenceManager::encodeHyperlink( const QString moduleName, const case Bible: //bibles or commentary keys need parsing case Commentary: { - /* CSwordModuleInfo* mod = CPointers::backend()->findModuleByName(moduleName); + /* CSwordModuleInfo* mod = CSwordBackend::instance()()->findModuleByName(moduleName); - ParseOptions options; - options.refDestinationModule = mod->name(); - options.refBase = - options.sourceLanguage = mod->module()->Lang(); - options.destinationLanguage = "en"; + ParseOptions options; + options.refDestinationModule = mod->name(); + options.refBase = + options.sourceLanguage = mod->module()->Lang(); + options.destinationLanguage = "en"; - ret.append( parseVerseReference(key, options) ); //we add the english key, so drag and drop will work in all cases*/ + ret.append( parseVerseReference(key, options) ); //we add the english key, so drag and drop will work in all cases*/ ret.append(key); break; } @@ -237,20 +235,6 @@ bool ReferenceManager::decodeHyperlink( const QString& hyperlink, QString& modul return true; } -const QString ReferenceManager::encodeReference(const QString &module, const QString &reference) { - //return QString("(%1)%2").arg(module).arg(reference); - return QString("(").append(module).append(")").append(reference); -} - -void ReferenceManager::decodeReference(QString &dragreference, QString &module, QString &reference) { - const int pos = dragreference.indexOf(")"); - const QString fallbackModule = dragreference.mid( 1, pos - 1); - dragreference = dragreference.mid(pos + 1); - - module = fallbackModule; - reference = dragreference; -} - /** Returns true if the parameter is a hyperlink. */ bool ReferenceManager::isHyperlink( const QString& hyperlink ) { return ( hyperlink.left(8) == "sword://") @@ -341,7 +325,7 @@ ReferenceManager::Type ReferenceManager::typeFromModule( const CSwordModuleInfo: /** Parses the given verse references using the given language and the module.*/ const QString ReferenceManager::parseVerseReference( const QString& ref, const ReferenceManager::ParseOptions& options) { - CSwordModuleInfo* const mod = CPointers::backend()->findModuleByName(options.refDestinationModule); + CSwordModuleInfo* const mod = CSwordBackend::instance()->findModuleByName(options.refDestinationModule); //Q_ASSERT(mod); tested later if (!mod) { @@ -371,19 +355,19 @@ const QString ReferenceManager::parseVerseReference( const QString& ref, const R CSwordVerseKey baseKey(0); baseKey.setLocale( sourceLanguage.toUtf8().constData() ); - baseKey.key( options.refBase ); //probably in the sourceLanguage + baseKey.setKey(options.refBase); //probably in the sourceLanguage baseKey.setLocale( "en_US" ); //english works in all environments as base -// CSwordVerseKey dummy(0); +// CSwordVerseKey dummy(0); //HACK: We have to workaround a Sword bug, we have to set the default locale to the same as the sourceLanguage ! - const QString oldLocaleName = CPointers::backend()->booknameLanguage(); - CPointers::backend()->booknameLanguage(sourceLanguage); + const QString oldLocaleName = CSwordBackend::instance()->booknameLanguage(); + CSwordBackend::instance()->booknameLanguage(sourceLanguage); sword::VerseKey dummy; dummy.setLocale( sourceLanguage.toUtf8().constData() ); Q_ASSERT( !strcmp(dummy.getLocale(), sourceLanguage.toUtf8().constData()) ); -// qDebug("Parsing '%s' in '%s' using '%s' as base, source lang '%s', dest lang '%s'", ref.latin1(), options.refDestinationModule.latin1(), baseKey.key().latin1(), sourceLanguage.latin1(), destinationLanguage.latin1()); +// qDebug("Parsing '%s' in '%s' using '%s' as base, source lang '%s', dest lang '%s'", ref.latin1(), options.refDestinationModule.latin1(), baseKey.key().latin1(), sourceLanguage.latin1(), destinationLanguage.latin1()); for (QStringList::iterator it = refList.begin(); it != refList.end(); it++) { //The listkey may contain more than one item, because a ref lik "Gen 1:3,5" is parsed into two single refs @@ -416,6 +400,6 @@ const QString ReferenceManager::parseVerseReference( const QString& ref, const R } - CPointers::backend()->booknameLanguage(oldLocaleName); + CSwordBackend::instance()->booknameLanguage(oldLocaleName); return ret; } diff --git a/src/backend/managers/referencemanager.h b/src/backend/managers/referencemanager.h index fdef8b2..a07b480 100644 --- a/src/backend/managers/referencemanager.h +++ b/src/backend/managers/referencemanager.h @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -47,20 +47,7 @@ bool decodeHyperlink( const QString& hyperlink, QString& module, QString& key, T * @return The encoded hyperlink */ const QString encodeHyperlink( const QString module, const QString key, const Type type); -/** -* Puts a module Name and a Reference together in the 'draggable' form -* (module)reference -* @param module The name of the module -* @param reference The key reference as text -* @return The encoded reference using module and reference -* @author Martin Gruner -*/ -const QString encodeReference(const QString &module, const QString &reference); -/** -* decodes a 'draggable' reference into a modulename and a reference -* @author Martin Gruner -*/ -void decodeReference(QString &dragreference, QString &module, QString &reference); + /** * Returns true if the parameter is a hyperlink. * @param hyperlink The string which is tested |