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.

csearchresultview.cpp 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 "csearchresultview.h"
  10. #include "backend/cswordversekey.h"
  11. #include "frontend/cdragdropmgr.h"
  12. #include "frontend/cexportmanager.h"
  13. #include "util/cresmgr.h"
  14. //TQt includes
  15. //KDE includes
  16. #include <tdelocale.h>
  17. #include <tdeaction.h>
  18. #include <tdepopupmenu.h>
  19. namespace Search {
  20. namespace Result {
  21. CSearchResultView::CSearchResultView(TQWidget* parent, const char* name) :
  22. TDEListView(parent, name), m_module(0) {
  23. initView();
  24. initConnections();
  25. }
  26. CSearchResultView::~CSearchResultView() {}
  27. /** Initializes the view of this widget. */
  28. void CSearchResultView::initView() {
  29. addColumn(i18n("Results"));
  30. setFullWidth(true);
  31. setSorting(-1);
  32. setDragEnabled(true);
  33. setSelectionModeExt(TDEListView::Extended);
  34. //setup the popup menu
  35. m_popup = new TDEPopupMenu(this);
  36. m_actions.copyMenu = new TDEActionMenu(i18n("Copy..."), CResMgr::searchdialog::result::foundItems::copyMenu::icon, TQT_TQOBJECT(m_popup));
  37. m_actions.copyMenu->setDelayed(false);
  38. m_actions.copy.result = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(copyItems()), TQT_TQOBJECT(this));
  39. m_actions.copyMenu->insert(m_actions.copy.result);
  40. m_actions.copy.resultWithText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(copyItemsWithText()), TQT_TQOBJECT(this));
  41. m_actions.copyMenu->insert(m_actions.copy.resultWithText);
  42. m_actions.copyMenu->plug(m_popup);
  43. m_actions.saveMenu = new TDEActionMenu(i18n("Save..."),CResMgr::searchdialog::result::foundItems::saveMenu::icon, TQT_TQOBJECT(m_popup));
  44. m_actions.saveMenu->setDelayed( false );
  45. m_actions.save.result = new TDEAction(i18n("Reference only"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveItems()), TQT_TQOBJECT(this));
  46. m_actions.saveMenu->insert(m_actions.save.result);
  47. m_actions.save.resultWithText = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(saveItemsWithText()), TQT_TQOBJECT(this));
  48. m_actions.saveMenu->insert(m_actions.save.resultWithText);
  49. m_actions.saveMenu->plug(m_popup);
  50. m_actions.printMenu = new TDEActionMenu(i18n("Print..."),CResMgr::searchdialog::result::foundItems::printMenu::icon, TQT_TQOBJECT(m_popup));
  51. m_actions.printMenu->setDelayed(false);
  52. m_actions.print.result = new TDEAction(i18n("Reference with text"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(printItems()), TQT_TQOBJECT(this));
  53. m_actions.printMenu->insert(m_actions.print.result);
  54. m_actions.printMenu->plug(m_popup);
  55. }
  56. /** No descriptions */
  57. void CSearchResultView::initConnections() {
  58. // connect(this, TQT_SIGNAL(executed(TQListViewItem*)),
  59. // this, TQT_SLOT(executed(TQListViewItem*)));
  60. connect(this, TQT_SIGNAL(currentChanged(TQListViewItem*)),
  61. this, TQT_SLOT(executed(TQListViewItem*)));
  62. connect(this, TQT_SIGNAL(contextMenu(TDEListView*, TQListViewItem*, const TQPoint&)),
  63. this, TQT_SLOT(showPopup(TDEListView*, TQListViewItem*, const TQPoint&)));
  64. }
  65. /** Setups the list with the given module. */
  66. void CSearchResultView::setupTree(CSwordModuleInfo* m) {
  67. clear();
  68. if (!m) {
  69. return;
  70. }
  71. m_module = m;
  72. sword::ListKey& result = m->searchResult();
  73. const int count = result.Count();
  74. if (!count) {
  75. return;
  76. }
  77. setUpdatesEnabled(false);
  78. TQListViewItem* oldItem = 0;
  79. TDEListViewItem* item = 0;
  80. for (int index = 0; index < count; index++) {
  81. item = new TDEListViewItem(this, oldItem);
  82. item->setText(0, TQString::fromUtf8(result.GetElement(index)->getText()));
  83. oldItem = item;
  84. }
  85. setUpdatesEnabled(true);
  86. setSelected(firstChild(), true);
  87. executed(currentItem());
  88. }
  89. void CSearchResultView::setupStrongsTree(CSwordModuleInfo* m, TQStringList* vList) {
  90. clear();
  91. if (!m) {
  92. return;
  93. }
  94. m_module = m;
  95. if (vList->count() <= 0) {
  96. return;
  97. }
  98. setUpdatesEnabled(false);
  99. TDEListViewItem* oldItem = 0;
  100. TDEListViewItem* item = 0;
  101. for ( TQStringList::Iterator it = vList->begin(); it != vList->end(); ++it ) {
  102. item = new TDEListViewItem(this, oldItem);
  103. item->setText(0, (*it));
  104. oldItem = item;
  105. }
  106. setUpdatesEnabled(true);
  107. setSelected(firstChild(), true);
  108. executed(currentItem());
  109. }
  110. /** Is connected to the signal executed, which is emitted when a mew item was chosen. */
  111. void CSearchResultView::executed(TQListViewItem* item) {
  112. // Q_ASSERT(item);
  113. // tqWarning("executed");
  114. emit keySelected(item->text(0));
  115. }
  116. /** Reimplementation to show the popup menu. */
  117. void CSearchResultView::showPopup(TDEListView*, TQListViewItem*, const TQPoint& point) {
  118. m_popup->exec(point);
  119. }
  120. /** No descriptions */
  121. void CSearchResultView::printItems() {
  122. TQPtrList<TQListViewItem> items = selectedItems();
  123. CExportManager mgr(i18n("Print search result..."), true, i18n("Printing search result"));
  124. TQStringList list;
  125. for (TQListViewItem* k = items.first(); k; k = items.next()) {
  126. list.append( k->text(0) );
  127. };
  128. mgr.printKeyList( list, module(), CBTConfig::getDisplayOptionDefaults(), CBTConfig::getFilterOptionDefaults() );
  129. }
  130. /** No descriptions */
  131. void CSearchResultView::saveItems() {
  132. CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
  133. CSwordModuleInfo* m = module();
  134. CSwordKey* k = 0;
  135. TQPtrList<TQListViewItem> items = selectedItems();
  136. TQPtrList<CSwordKey> keys;
  137. for (TQListViewItem* i = items.first(); i; i = items.next()) {
  138. k = CSwordKey::createInstance( m );
  139. k->key(i->text(0));
  140. keys.append( k );
  141. };
  142. mgr.saveKeyList( keys, CExportManager::Text, false);
  143. keys.setAutoDelete(true);
  144. keys.clear(); //delete all the keys we created
  145. }
  146. /** No descriptions */
  147. void CSearchResultView::saveItemsWithText() {
  148. CExportManager mgr(i18n("Save search result..."), true, i18n("Saving search result"));
  149. CSwordModuleInfo* m = module();
  150. CSwordKey* k = 0;
  151. TQPtrList<TQListViewItem> items = selectedItems();
  152. TQPtrList<CSwordKey> keys;
  153. for (TQListViewItem* i = items.first(); i; i = items.next()) {
  154. k = CSwordKey::createInstance( m );
  155. k->key(i->text(0));
  156. keys.append( k );
  157. };
  158. mgr.saveKeyList( keys, CExportManager::Text, true);
  159. keys.setAutoDelete(true);
  160. keys.clear(); //delete all the keys we created
  161. }
  162. /** No descriptions */
  163. void CSearchResultView::copyItems() {
  164. CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
  165. CSwordModuleInfo* m = module();
  166. CSwordKey* k = 0;
  167. TQPtrList<TQListViewItem> items = selectedItems();
  168. TQPtrList<CSwordKey> keys;
  169. for (TQListViewItem* i = items.first(); i; i = items.next()) {
  170. k = CSwordKey::createInstance( m );
  171. k->key(i->text(0));
  172. keys.append( k );
  173. };
  174. mgr.copyKeyList( keys, CExportManager::Text, false);
  175. keys.setAutoDelete(true);
  176. keys.clear(); //delete all the keys we created
  177. }
  178. /** No descriptions */
  179. void CSearchResultView::copyItemsWithText() {
  180. CExportManager mgr(i18n("Copy search result..."), true, i18n("Copying search result"));
  181. CSwordModuleInfo* m = module();
  182. CSwordKey* k = 0;
  183. TQPtrList<TQListViewItem> items = selectedItems();
  184. TQPtrList<CSwordKey> keys;
  185. for (TQListViewItem* i = items.first(); i; i = items.next()) {
  186. k = CSwordKey::createInstance( m );
  187. k->key(i->text(0));
  188. keys.append( k );
  189. };
  190. mgr.copyKeyList( keys, CExportManager::Text, true);
  191. keys.setAutoDelete(true);
  192. keys.clear(); //delete all the keys we created
  193. }
  194. /** Returns the module which is currently used. */
  195. CSwordModuleInfo* const CSearchResultView::module() {
  196. return m_module;
  197. }
  198. TQDragObject* CSearchResultView::dragObject() {
  199. //return a valid DragObject to make DnD possible!
  200. /*
  201. * First get all selected items and fill with them the dndItems list. The return the TQDragObject we got from CDRagDropMgr
  202. */
  203. CDragDropMgr::ItemList dndItems;
  204. TQPtrList<TQListViewItem> items = selectedItems();
  205. for (items.first(); items.current(); items.next()) {
  206. dndItems.append( CDragDropMgr::Item(m_module->name(), items.current()->text(0), TQString()) ); //no description
  207. };
  208. return CDragDropMgr::dragObject(dndItems, viewport());
  209. }
  210. } //end of namespace Search::Result
  211. } //end of namespace
  212. #include "csearchresultview.moc"