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.

clanguagemgr.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 CLANGUAGEMGR_H
  10. #define CLANGUAGEMGR_H
  11. //Qt includes
  12. #include <tqstring.h>
  13. #include <tqstringlist.h>
  14. #include <tqvaluelist.h>
  15. #include <tqmap.h>
  16. #include <tqdict.h>
  17. /** Manages the anguages of BibleTime and provides functions to work with them.
  18. * @author The BibleTime team
  19. */
  20. class CLanguageMgr {
  21. public:
  22. /** Language container.
  23. * This class (Language) contains the information about the chosen language.
  24. */
  25. class Language {
  26. public:
  27. /** Default constructor of a language object.
  28. * Uses the abbreviation parameter to lookup the
  29. * language name and to be able to return the name, flag etc.
  30. * Possible values for abbrev are de, en, fr, it etc.
  31. */
  32. Language();
  33. /** Copy constructor.
  34. */
  35. Language(const Language&);
  36. /** Constructor which takes all necessary data.
  37. */
  38. Language(const TQString& abbrev, const TQString& englishName, const TQString& translatedName, const TQStringList& altAbbrevs = TQStringList());
  39. /** Destructor.
  40. */
  41. ~Language();
  42. /** Returns the abbreviation.
  43. * @return The abbreviation of the chosen language.
  44. */
  45. inline const TQString& abbrev() const;
  46. /** Returns the translated name.
  47. * @return The translated name of the language.
  48. */
  49. inline const TQString& translatedName() const;
  50. //always define inlines in the header file, or make them not inline.
  51. /** The english name of the language.
  52. * @return The english name of the chosen language.
  53. */
  54. inline const TQString& name() const {
  55. return m_englishName;
  56. }
  57. /** The alternative abbreviations which are avalable for this language.
  58. * @return A pointer to the list of alternate abbreviations
  59. */
  60. inline const TQStringList* const alternativeAbbrevs() const {
  61. return m_altAbbrevs;
  62. };
  63. /**
  64. * Returns true if this language object is valid, i.e. has an abbrev and name.
  65. * @return True if the data is valid for this language.
  66. */
  67. inline const bool isValid() const;
  68. private:
  69. TQString m_abbrev;
  70. TQString m_englishName;
  71. TQString m_translatedName;
  72. TQStringList* m_altAbbrevs;
  73. };
  74. typedef TQPtrList<CLanguageMgr::Language> LanguageList;
  75. typedef TQDict<Language> LangMap;
  76. typedef TQDictIterator<Language> LangMapIterator;
  77. /** Constructor.
  78. */
  79. CLanguageMgr();
  80. /** Destructor
  81. */
  82. virtual ~CLanguageMgr();
  83. /**
  84. * Returns the standard languages available as standard. Does nothing for Sword.
  85. * @return A TQDict<Language> map which contains all known languages
  86. */
  87. inline const CLanguageMgr::LangMap* const languages() const;
  88. /**
  89. * Returns the languages which are available. The languages cover all available modules, but nothing more.
  90. * @return A map of all languages with modules available for them
  91. */
  92. const CLanguageMgr::LangMap& availableLanguages();
  93. /** Language for abbreviation.
  94. * @param abbrev The language abbreviation
  95. * @return Pointer to a language for the given string abbreviation.
  96. */
  97. const CLanguageMgr::Language* const languageForAbbrev( const TQString& abbrev ) const;
  98. /** Language for english name.
  99. * @param abbrev The english language name.
  100. * @return Pointer to a language for the given name
  101. */
  102. const CLanguageMgr::Language* const languageForName( const TQString& language ) const;
  103. /** Language for translated language name.
  104. * @param abbrev The translated language name
  105. * @return Pointer to a language for the given translated language name
  106. */
  107. const CLanguageMgr::Language* const languageForTranslatedName( const TQString& language ) const;
  108. /** Default language so we don't return NULL pointers.
  109. * @return Pointer to the default language
  110. */
  111. inline const CLanguageMgr::Language* const defaultLanguage() const;
  112. private:
  113. void init();
  114. inline const TQStringList makeStringList(const TQString& abbrevs) {
  115. return TQStringList::split( ";", abbrevs, false );
  116. }
  117. mutable LangMap m_langMap;
  118. Language m_defaultLanguage;
  119. //typedef TQPtrList<CLanguageMgr::Language> LanguageList;
  120. static LanguageList m_langList;
  121. static LanguageList m_cleanupLangPtrs;
  122. struct ModuleCache {
  123. unsigned int moduleCount;
  124. LangMap availableLanguages;
  125. }
  126. m_availableModulesCache;
  127. };
  128. /** Returns true if this language object is valid, i.e. has an abbrev and name. */
  129. inline const bool CLanguageMgr::Language::isValid() const {
  130. return (!abbrev().isEmpty() && !name().isEmpty());
  131. }
  132. inline const TQString& CLanguageMgr::Language::abbrev() const {
  133. if (m_altAbbrevs && m_abbrev.isEmpty() && m_altAbbrevs->count()) { //no standard abbrev but alternative ones
  134. return m_altAbbrevs->first();
  135. }
  136. return m_abbrev;
  137. }
  138. inline const TQString& CLanguageMgr::Language::translatedName() const {
  139. return m_translatedName;
  140. }
  141. inline const CLanguageMgr::LangMap* const CLanguageMgr::languages() const {
  142. return &m_langMap;
  143. }
  144. inline const CLanguageMgr::Language* const CLanguageMgr::defaultLanguage() const {
  145. return &m_defaultLanguage;
  146. }
  147. #endif