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.

cmoduleresultview.cpp 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. #include "cmoduleresultview.h"
  10. #include "backend/cswordmoduleinfo.h"
  11. #include "frontend/util/csortlistviewitem.h"
  12. #include "frontend/cexportmanager.h"
  13. #include "util/cresmgr.h"
  14. #include "util/ctoolclass.h"
  15. //TQt includes
  16. //KDE includes
  17. #include <tdelocale.h>
  18. #include <tdeaction.h>
  19. #include <tdepopupmenu.h>
  20. namespace Search {
  21. namespace Result {
  22. /********************************************
  23. ************ ModuleResultList **************
  24. ********************************************/
  25. CModuleResultView::CModuleResultView(TQWidget* parent, const char* name) :
  26. TDEListView(parent, name) {
  27. initView();
  28. initConnections();
  29. strongsResults = 0;
  30. };
  31. CModuleResultView::~CModuleResultView() {}
  32. ;
  33. /** Initializes this widget. */
  34. void CModuleResultView::initView() {
  35. addColumn(i18n("Work"));
  36. addColumn(i18n("Hits"));
  37. setFullWidth(true);
  38. // setFullWidth(true);
  39. setSorting(0, true);
  40. setSorting(1, true);
  41. setAllColumnsShowFocus(true);
  42. //setup the popup menu
  43. m_popup = new TDEPopupMenu(this);
  44. // m_popup->insertTitle(i18n("Bible window"));
  45. m_actions.copyMenu = new TDEActionMenu(i18n("Copy..."), CResMgr::searchdialog::result::moduleList::copyMenu::icon, TQT_TQOBJECT(m_popup));
  46. m_actions.copyMenu->setDelayed(false);
  47. m_actions.copy.result = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(copyResult()), TQT_TQOBJECT(this));
  48. m_actions.copyMenu->insert(m_actions.copy.result);
  49. m_actions.copy.resultWithText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(copyResultWithText()), TQT_TQOBJECT(this));
  50. m_actions.copyMenu->insert(m_actions.copy.resultWithText);
  51. m_actions.copyMenu->plug(m_popup);
  52. m_actions.saveMenu = new TDEActionMenu(i18n("Save..."), CResMgr::searchdialog::result::moduleList::saveMenu::icon, TQT_TQOBJECT(m_popup));
  53. m_actions.saveMenu->setDelayed( false );
  54. m_actions.save.result = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveResult()), TQT_TQOBJECT(this));
  55. m_actions.saveMenu->insert(m_actions.save.result);
  56. m_actions.save.resultWithText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveResultWithText()), TQT_TQOBJECT(this));
  57. m_actions.saveMenu->insert(m_actions.save.resultWithText);
  58. m_actions.saveMenu->plug(m_popup);
  59. m_actions.printMenu = new TDEActionMenu(i18n("Print..."), CResMgr::searchdialog::result::moduleList::printMenu::icon, TQT_TQOBJECT(m_popup));
  60. m_actions.printMenu->setDelayed(false);
  61. m_actions.print.result = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printResult()), TQT_TQOBJECT(this));
  62. m_actions.printMenu->insert(m_actions.print.result);
  63. m_actions.printMenu->plug(m_popup);
  64. }
  65. /** Initializes the connections of this widget, */
  66. void CModuleResultView::initConnections() {
  67. connect(this, TQT_SIGNAL(currentChanged(TQListViewItem*)),
  68. this, TQT_SLOT(executed(TQListViewItem*)));
  69. connect(this, TQT_SIGNAL(contextMenu(TDEListView*, TQListViewItem*, const TQPoint&)),
  70. this, TQT_SLOT(showPopup(TDEListView*, TQListViewItem*, const TQPoint&)));
  71. }
  72. /** Setups the tree using the given list of modules. */
  73. void CModuleResultView::setupTree( ListCSwordModuleInfo modules, const TQString& searchedText ) {
  74. clear();
  75. util::CSortListViewItem* item = 0;
  76. util::CSortListViewItem* oldItem = 0;
  77. sword::ListKey result;
  78. if (strongsResults) {
  79. delete strongsResults;
  80. strongsResults = 0;
  81. }
  82. bool strongsAvailable = false;
  83. ListCSwordModuleInfo::iterator end_it = modules.end();
  84. for (ListCSwordModuleInfo::iterator it(modules.begin()); it != end_it; ++it) {
  85. // for (modules.first(); modules.current(); modules.next()) {
  86. result = (*it)->searchResult();
  87. item = new util::CSortListViewItem(this, (*it)->name(), TQString::number(result.Count()) );
  88. item->setColumnSorting(1, util::CSortListViewItem::Number);
  89. item->setPixmap(0,CToolClass::getIconForModule(*it) );
  90. oldItem = item;
  91. //----------------------------------------------------------------------
  92. // we need to make a decision here. Either don't show any Strong's
  93. // number translations, or show the first one in the search text, or
  94. // figure out how to show them all.
  95. // I choose option number 2 at this time.
  96. //----------------------------------------------------------------------
  97. int sstIndex, sTokenIndex; // strong search text index for finding "strong:"
  98. if ((sstIndex = searchedText.find("strong:", 0)) != -1) {
  99. TQString sNumber;
  100. //--------------------------------------------------
  101. // get the strongs number from the search text
  102. //--------------------------------------------------
  103. // first find the first space after "strong:"
  104. // this should indicate a change in search token
  105. sstIndex = sstIndex + 7;
  106. sTokenIndex = searchedText.find(" ", sstIndex);
  107. sNumber = searchedText.mid(sstIndex, sTokenIndex - sstIndex);
  108. setupStrongsResults((*it), item, sNumber);
  109. item->setOpen(true);
  110. strongsAvailable = true;
  111. }
  112. };
  113. //Allow to hide the module strongs if there are any available
  114. setRootIsDecorated( strongsAvailable );
  115. setSelected(currentItem(), true);
  116. executed(currentItem());
  117. }
  118. void CModuleResultView::setupStrongsResults(CSwordModuleInfo* module, TQListViewItem* parent,
  119. const TQString& sNumber) {
  120. TQString lText;
  121. util::CSortListViewItem* item = 0;
  122. strongsResults = new StrongsResultClass(module, sNumber);
  123. for (int cnt = 0; cnt < strongsResults->Count(); ++cnt) {
  124. lText = strongsResults->keyText(cnt);
  125. item = new util::CSortListViewItem(parent, lText, TQString::number(strongsResults->keyCount(cnt)));
  126. item->setColumnSorting(1, util::CSortListViewItem::Number);
  127. }
  128. }
  129. /** Is executed when an item was selected in the list. */
  130. void CModuleResultView::executed( TQListViewItem* i ) {
  131. TQString itemText, lText;
  132. if (CSwordModuleInfo* m = CPointers::backend()->findModuleByName(i->text(0))) {
  133. emit moduleChanged();
  134. emit moduleSelected(m);
  135. return;
  136. }
  137. if (!strongsResults) {
  138. return;
  139. }
  140. itemText = i->text(0);
  141. for (int cnt = 0; cnt < strongsResults->Count(); cnt++) {
  142. lText = strongsResults->keyText(cnt);
  143. if (lText == itemText) {
  144. //clear the verses list
  145. emit moduleChanged();
  146. emit strongsSelected(activeModule(), strongsResults->getKeyList(cnt));
  147. return;
  148. }
  149. }
  150. }
  151. /** Returns the currently active module. */
  152. CSwordModuleInfo* const CModuleResultView::activeModule() {
  153. Q_ASSERT(currentItem());
  154. TQListViewItem* item = currentItem();
  155. if (!item) {
  156. return 0;
  157. }
  158. // we need to find the parent most node because that is the node
  159. // that is the module name.
  160. while (item->parent()) {
  161. item = item->parent();
  162. }
  163. if (item) {
  164. return CPointers::backend()->findModuleByName(item->text(0));
  165. }
  166. return 0;
  167. }
  168. /** No descriptions */
  169. void CModuleResultView::showPopup(TDEListView*, TQListViewItem*, const TQPoint& point) {
  170. //make sure that all entries have the correct status
  171. m_popup->exec(point);
  172. }
  173. /** Copies the whole search result into the clipboard. */
  174. void CModuleResultView::copyResult() {
  175. if (CSwordModuleInfo* m = activeModule()) {
  176. sword::ListKey result = m->searchResult();
  177. CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
  178. mgr.copyKeyList(&result,m,CExportManager::Text,false);
  179. };
  180. }
  181. /** Copies the whole search result with the text into the clipboard. */
  182. void CModuleResultView::copyResultWithText() {
  183. if (CSwordModuleInfo* m = activeModule()) {
  184. sword::ListKey result = m->searchResult();
  185. CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
  186. mgr.copyKeyList(&result,m,CExportManager::Text,true);
  187. };
  188. }
  189. /** Saves the search result keys. */
  190. void CModuleResultView::saveResult() {
  191. if (CSwordModuleInfo* m = activeModule()) {
  192. sword::ListKey result = m->searchResult();
  193. CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
  194. mgr.saveKeyList(&result,m,CExportManager::Text,false);
  195. };
  196. }
  197. /** Saves the search result with it's text. */
  198. void CModuleResultView::saveResultWithText() {
  199. if (CSwordModuleInfo* m = activeModule()) {
  200. sword::ListKey result = m->searchResult();
  201. CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
  202. mgr.saveKeyList(&result,m,CExportManager::Text,true);
  203. };
  204. }
  205. /** Appends the whole search result to the printer queue. */
  206. void CModuleResultView::printResult() {
  207. if (CSwordModuleInfo* m = activeModule()) {
  208. sword::ListKey result = m->searchResult();
  209. CExportManager mgr(i18n("Print search result..."), true, i18n("Printing search result"));
  210. mgr.printKeyList(&result,m,CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults());
  211. };
  212. }
  213. } //end of namespace Search.Result
  214. } //end of namespace Search
  215. #include "cmoduleresultview.moc"