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.

bibletime_dcop.cpp 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. //BibleTime includes
  10. #include "bibletime.h"
  11. //frontend includes
  12. #include "frontend/cmdiarea.h"
  13. #include "frontend/cbtconfig.h"
  14. #include "frontend/searchdialog/csearchdialog.h"
  15. //Sword includes
  16. #include <versekey.h>
  17. #include <listkey.h>
  18. //helper function
  19. void BibleTime::syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const TQString& key) {
  20. tqDebug("Syncing modules by type to key %s", key.latin1());
  21. TQPtrList<TQWidget> windows = m_mdi->usableWindowList();
  22. for (TQWidget* w = windows.first(); w; w = windows.next()) {
  23. CDisplayWindow* d = dynamic_cast<CDisplayWindow*>(w);
  24. Q_ASSERT(d);
  25. if (d && d->modules().count() && d->modules().first()->type() == type) {
  26. d->lookup(key);
  27. }
  28. }
  29. }
  30. void BibleTime::closeAllModuleWindows() {
  31. tqDebug("DCOP: close all windows now...");
  32. m_mdi->deleteAll();
  33. }
  34. void BibleTime::syncAllBibles(const TQString& key) {
  35. tqDebug("DCOP: syncing all bibles ...");
  36. syncAllModulesByType(CSwordModuleInfo::Bible, key);
  37. }
  38. void BibleTime::syncAllCommentaries(const TQString& key) {
  39. tqDebug("DCOP: syncing all commentaries ...");
  40. syncAllModulesByType(CSwordModuleInfo::Commentary, key);
  41. }
  42. void BibleTime::syncAllLexicons(const TQString& key) {
  43. tqDebug("DCOP: syncing all lexicons ...");
  44. syncAllModulesByType(CSwordModuleInfo::Lexicon, key);
  45. }
  46. void BibleTime::syncAllVerseBasedModules(const TQString& key) {
  47. tqDebug("DCOP: syncing all verse based modules ...");
  48. syncAllModulesByType(CSwordModuleInfo::Bible, key);
  49. syncAllModulesByType(CSwordModuleInfo::Commentary, key);
  50. }
  51. void BibleTime::openWindow(const TQString& moduleName, const TQString& key) {
  52. tqDebug("DCOP: open window for module %s and key %s...", moduleName.latin1(), key.latin1());
  53. CSwordModuleInfo* module = CPointers::backend()->findModuleByName(moduleName);
  54. Q_ASSERT(module);
  55. if (module) {
  56. createReadDisplayWindow(module, key);
  57. }
  58. }
  59. void BibleTime::openDefaultBible(const TQString& key) {
  60. tqDebug("DCOP: open default bible ...");
  61. CSwordModuleInfo* mod = CBTConfig::get
  62. (CBTConfig::standardBible);
  63. if (mod) {
  64. openWindow(mod->name(), key);
  65. }
  66. }
  67. TQStringList BibleTime::searchInModule(const TQString& moduleName, const TQString& searchText) {
  68. tqDebug("DCOP: searchInModule %s ...", moduleName.latin1());
  69. TQStringList ret;
  70. CSwordModuleInfo* mod = CPointers::backend()->findModuleByName(moduleName);
  71. //TODO: Check this
  72. Q_ASSERT(mod);
  73. if (mod) {
  74. //mod->search(searchText, CSwordModuleSearch::multipleWords, sword::ListKey());
  75. sword::ListKey scope;
  76. mod->searchIndexed( searchText, scope );
  77. sword::ListKey result = mod->searchResult();
  78. const TQString lead = TQString("[%1] ").arg(moduleName);
  79. ;
  80. for ( int i = 0; i < result.Count(); ++i ) {
  81. sword::SWKey* key = result.getElement(i);
  82. Q_ASSERT(key);
  83. if (mod->type() == CSwordModuleInfo::Bible || mod->type() == CSwordModuleInfo::Commentary) {
  84. sword::VerseKey vk(key->getText());
  85. ret << lead + TQString::fromUtf8( vk.getOSISRef() );
  86. }
  87. else {
  88. ret << lead + TQString::fromUtf8( key->getText() );
  89. }
  90. }
  91. }
  92. return ret;
  93. }
  94. TQStringList BibleTime::searchInOpenModules(const TQString& searchText) {
  95. tqDebug("DCOP: search in open modules ...");
  96. TQStringList ret;
  97. TQWidgetList windows = m_mdi->windowList();
  98. for ( int i = 0; i < static_cast<int>(windows.count()); ++i ) {
  99. CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(windows.at(i));
  100. if (w) {
  101. ListCSwordModuleInfo windowModules = w->modules();
  102. ListCSwordModuleInfo::iterator end_it = windowModules.end();
  103. for (ListCSwordModuleInfo::iterator it(windowModules.begin()); it != end_it; ++it) {
  104. ret += searchInModule((*it)->name(), searchText);
  105. };
  106. };
  107. };
  108. return ret;
  109. }
  110. TQStringList BibleTime::searchInDefaultBible(const TQString& searchText) {
  111. CSwordModuleInfo* bible = CBTConfig::get
  112. (CBTConfig::standardBible);
  113. return searchInModule(bible->name(), searchText);
  114. }
  115. TQString BibleTime::getCurrentReference() {
  116. tqDebug("BibleTime::getCurrentReference");
  117. TQString ret = TQString();
  118. CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(m_mdi->activeWindow());
  119. Q_ASSERT(w);
  120. if (w) {
  121. TQString modType;
  122. Q_ASSERT(w->modules().first());
  123. switch (w->modules().first()->type()) {
  124. case CSwordModuleInfo::Bible:
  125. modType = "BIBLE";
  126. break;
  127. case CSwordModuleInfo::Commentary:
  128. modType = "COMMENTARY";
  129. break;
  130. case CSwordModuleInfo::GenericBook:
  131. modType = "BOOK";
  132. break;
  133. case CSwordModuleInfo::Lexicon:
  134. modType = "LEXICON";
  135. break;
  136. default:
  137. modType = "UNSUPPORTED";
  138. break;
  139. }
  140. ret.append("[").append(w->modules().first()->name()).append("] ");
  141. ret.append("[").append(modType).append("] ");
  142. CSwordVerseKey* vk = dynamic_cast<CSwordVerseKey*>( w->key() );
  143. if (vk) {
  144. ret.append( vk->getOSISRef() );
  145. }
  146. else {
  147. ret.append( w->key()->key() );
  148. }
  149. }
  150. return ret;
  151. }
  152. TQStringList BibleTime::getModulesOfType(const TQString& type) {
  153. TQStringList ret;
  154. CSwordModuleInfo::ModuleType modType = CSwordModuleInfo::Unknown;
  155. if (type == "BIBLES") {
  156. modType = CSwordModuleInfo::Bible;
  157. }
  158. else if (type == "COMMENTARIES") {
  159. modType = CSwordModuleInfo::Commentary;
  160. }
  161. else if (type == "LEXICONS") {
  162. modType = CSwordModuleInfo::Lexicon;
  163. }
  164. else if (type == "BOOKS") {
  165. modType = CSwordModuleInfo::GenericBook;
  166. }
  167. ListCSwordModuleInfo modList = CPointers::backend()->moduleList();
  168. for (ListCSwordModuleInfo::iterator it( modList.begin() ); it != modList.end(); ++it) {
  169. if ((*it)->type() == modType) {
  170. ret.append( (*it)->name() );
  171. }
  172. }
  173. return ret;
  174. }
  175. void BibleTime::reloadModules() {
  176. //m_backend->reloadModules();
  177. slotSwordSetupChanged();
  178. }