Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cswordbackend.h 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #ifndef CSWORDBACKEND_H
  10. #define CSWORDBACKEND_H
  11. //BibleTime includes
  12. #include "cswordmoduleinfo.h"
  13. //#include "centrydisplay.h"
  14. //Qt includes
  15. #include <tqptrlist.h>
  16. #include <tqmap.h>
  17. #include <tqstring.h>
  18. #include <tqstringlist.h>
  19. //Sword includes
  20. #include <swmgr.h>
  21. #include <swbuf.h>
  22. #include <swmodule.h>
  23. #include <swversion.h>
  24. #include <localemgr.h>
  25. #include <utilstr.h>
  26. using namespace sword;
  27. namespace Rendering {
  28. class CEntryDisplay;
  29. class CChapterDisplay;
  30. class CBookDisplay;
  31. }
  32. /** The backend layer main class.
  33. * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr
  34. * to provide functions of Sword.
  35. *
  36. * @short The backend implementation of Sword
  37. * @author The BibleTime team
  38. * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $
  39. */
  40. class CSwordBackend : public sword::SWMgr {
  41. public:
  42. /** Filter options. Filter options to
  43. * control the text display of modules. Uses int and not bool because not all
  44. * options have just two toggle values.
  45. */
  46. struct FilterOptions {
  47. int footnotes; /**< 0 for disabled, 1 for enabled */
  48. int strongNumbers; /**< 0 for disabled, 1 for enabled */
  49. int headings; /**< 0 for disabled, 1 for enabled */
  50. int morphTags; /**< 0 for disabled, 1 for enabled */
  51. int lemmas; /**< 0 for disabled, 1 for enabled */
  52. int hebrewPoints; /**< 0 for disabled, 1 for enabled */
  53. int hebrewCantillation; /**< 0 for disabled, 1 for enabled */
  54. int greekAccents; /**< 0 for disabled, 1 for enabled */
  55. int textualVariants; /**< Number n to enabled the n-th variant */
  56. int redLetterWords; /**< 0 for disabled, 1 for enabled */
  57. int scriptureReferences; /**< 0 for disabled, 1 for enabled */
  58. int morphSegmentation; /**< 0 for disabled, 1 for enabled */
  59. };
  60. /** Control the display of a text.
  61. */
  62. struct DisplayOptions {
  63. int lineBreaks;
  64. int verseNumbers;
  65. };
  66. /** The error codes which may be returned by the @ref Load() call.
  67. */
  68. enum LoadError { // the values exist to cast from the char return of SWMgr::Load
  69. NoSwordConfig = -1,
  70. NoError = 0,
  71. NoModules = 1
  72. };
  73. /**
  74. * The constructor of the Sword backend.
  75. * It creates the SWModule objects using SWMgr's methods, it adds the necessary
  76. * filters for the module format.
  77. */
  78. CSwordBackend();
  79. /**
  80. * The constructor of the Sword backend.
  81. * @param path The path which is used to load modules
  82. * @param augmentHome True if the $HOME/.sword/ modules should be augmented with the other modules
  83. */
  84. CSwordBackend( const TQString& path, const bool augmentHome = true );
  85. /**
  86. * The destrctor of this backend. This function shuts the modules down using @ref shutdownModules.
  87. */
  88. virtual ~CSwordBackend();
  89. /**
  90. * This function returns the list of available modules managed by this backend.
  91. * You have to call initModules() first;
  92. *
  93. * @return The list of modules managed by this backend
  94. */
  95. inline virtual ListCSwordModuleInfo& moduleList();
  96. /**
  97. * Initializes the Sword modules.
  98. *
  99. * @return True if the initializiation was succesful, otherwise return false.
  100. */
  101. virtual const CSwordBackend::LoadError initModules();
  102. /**
  103. * This function deinitializes the modules and deletes them.
  104. *
  105. * @return True if it was succesful, otherwise return false
  106. */
  107. virtual const bool shutdownModules();
  108. /**
  109. * Sets the given options enabled or disabled depending on the second parameter.
  110. *
  111. * @param type This is the type this function should set enabled or disabled
  112. * @param enable If this is true the option will be enabled, otherwise it will be disabled.
  113. */
  114. void setOption( const CSwordModuleInfo::FilterTypes type, const int state );
  115. void setFilterOptions( const CSwordBackend::FilterOptions options );
  116. void setDisplayOptions( const CSwordBackend::DisplayOptions options );
  117. /**
  118. * Returns true if the given option is enabled.
  119. *
  120. * @return Returns true if the options given as aparameter is switched on at this time, otherwise return false.
  121. */
  122. virtual const bool isOptionEnabled( const CSwordModuleInfo::FilterTypes type);
  123. /**
  124. * Sets the language for the international booknames of Sword.
  125. * @param langName The abbreviation string which should be used for the Sword backend
  126. */
  127. const TQString booknameLanguage( const TQString& langName = TQString::null );
  128. /**
  129. * This function searches for a module with the specified description
  130. * @param description The description of the desired module
  131. * @return pointer to the desired module; null if no module has the specified description
  132. */
  133. virtual CSwordModuleInfo* const findModuleByDescription(const TQString& description);
  134. /**
  135. * This function searches for a module with the specified description
  136. * @param description The description of the desired module
  137. * @return pointer to the desired module; null if no module has the specified description
  138. */
  139. const TQString findModuleNameByDescription(const TQString& description);
  140. /**
  141. * This function searches for a module with the specified name
  142. * @param name The name of the desired module
  143. * @return Pointer to the desired module; null if no module has the specified name
  144. */
  145. CSwordModuleInfo* const findModuleByName(const TQString& name);
  146. /**
  147. * This function searches for a module with the specified sword module as module() object!
  148. * @param swmodule to a Sword module
  149. * @return pointer to the desired module; null if no module has the specified name
  150. */
  151. CSwordModuleInfo* const findSwordModuleByPointer(const sword::SWModule* const swmodule);
  152. /**
  153. * This function searches for a module which is the same as the passed module.
  154. * @param module The module which should be used for searching the new one. May be child of a different backend.
  155. * @return Pointer to the desired module; null if no module has the specified name
  156. */
  157. CSwordModuleInfo* const findModuleByPointer(const CSwordModuleInfo* const module);
  158. /**
  159. * @return Our global config object which contains the configs of all modules merged together.
  160. */
  161. inline sword::SWConfig* const getConfig() const;
  162. /**
  163. * Tries to find the config object for the module. The second paramter will be the found config.
  164. * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state.
  165. */
  166. const bool moduleConfig(const TQString& module, sword::SWConfig& moduleConfig );
  167. /**
  168. * Returns the text used for the option given as parameter.
  169. * @param The paramter enum
  170. * @return The name of the option given by the parameter
  171. */
  172. static const TQString optionName( const CSwordModuleInfo::FilterTypes option );
  173. /**
  174. * Returns the text used for the option given as parameter.
  175. */
  176. static const TQString configOptionName( const CSwordModuleInfo::FilterTypes option );
  177. /**
  178. * Returns the translated name of the option given as parameter.
  179. * @param The translated option name
  180. */
  181. static const TQString translatedOptionName(const CSwordModuleInfo::FilterTypes option );
  182. /**
  183. * Returns the version of the Sword library.
  184. * @return The version used by this backend
  185. */
  186. inline virtual const sword::SWVersion Version();
  187. /**
  188. * Reload all Sword modules.
  189. */
  190. void reloadModules();
  191. /** Sword prefix list.
  192. * @return A list of all known Sword prefix dirs
  193. */
  194. const TQStringList swordDirList();
  195. protected:
  196. /**
  197. * Adds a render filter to the module.
  198. * @param module Add a render filter to this module!
  199. */
  200. virtual void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section);
  201. /**
  202. * Initializes the filters provided by BibleTime.
  203. */
  204. virtual void filterInit();
  205. private:
  206. // Filters
  207. struct Filters {
  208. sword::SWFilter *gbf;
  209. sword::SWFilter *plain;
  210. sword::SWFilter *thml;
  211. sword::SWFilter *osis;
  212. }
  213. m_filters;
  214. struct Displays {
  215. Rendering::CChapterDisplay* chapter;
  216. Rendering::CEntryDisplay* entry;
  217. Rendering::CBookDisplay* book;
  218. }
  219. m_displays;
  220. ListCSwordModuleInfo m_moduleList;
  221. TQMap<TQString, TQString> m_moduleDescriptionMap;
  222. };
  223. /**Returns The list of modules managed by this backend*/
  224. inline ListCSwordModuleInfo& CSwordBackend::moduleList() {
  225. return m_moduleList;
  226. }
  227. /** 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. */
  228. inline sword::SWConfig* const CSwordBackend::getConfig() const {
  229. return config;
  230. }
  231. /** Returns the version of the Sword library. */
  232. inline const sword::SWVersion CSwordBackend::Version() {
  233. return sword::SWVersion::currentVersion;
  234. }
  235. #endif