Bibletime – a bible study tool
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

csearchdialog.cpp 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "csearchdialog.h"
  10. #include "csearchanalysis.h"
  11. #include "backend/cswordmodulesearch.h"
  12. #include "backend/cswordkey.h"
  13. #include "backend/cswordversekey.h"
  14. #include "frontend/cbtconfig.h"
  15. #include "frontend/cmoduleindexdialog.h"
  16. #include "util/cresmgr.h"
  17. #include "util/ctoolclass.h"
  18. //TQt includes
  19. #include <tqhbox.h>
  20. #include <tqvbox.h>
  21. #include <tqptrlist.h>
  22. #include <tqpainter.h>
  23. #include <tqlayout.h>
  24. #include <tqmap.h>
  25. #include <tqlineedit.h>
  26. #include <tqtextedit.h>
  27. #include <tqlabel.h>
  28. #include <tqsizepolicy.h>
  29. #include <tqpushbutton.h>
  30. #include <tqheader.h>
  31. #include <tqregexp.h>
  32. #include <tqmessagebox.h>
  33. //KDE includes
  34. #include <tdeapplication.h>
  35. #include <tdefiledialog.h>
  36. #include <tdelocale.h>
  37. #include <kiconloader.h>
  38. namespace Search {
  39. static CSearchDialog* m_staticDialog = 0;
  40. void CSearchDialog::openDialog(const ListCSwordModuleInfo modules, const TQString& searchText, TQWidget* parentDialog) {
  41. if (!m_staticDialog) {
  42. m_staticDialog = new CSearchDialog(parentDialog);
  43. };
  44. m_staticDialog->reset();
  45. if (modules.count()) {
  46. m_staticDialog->setModules(modules);
  47. }
  48. else {
  49. m_staticDialog->showModulesSelector();
  50. }
  51. m_staticDialog->setSearchText(searchText);
  52. if (m_staticDialog->isHidden()) {
  53. m_staticDialog->show();
  54. }
  55. if (modules.count() && !searchText.isEmpty()) {
  56. m_staticDialog->startSearch();
  57. }
  58. // moved these to after the startSearch() because
  59. // the progress dialog caused them to loose focus.
  60. m_staticDialog->raise();
  61. m_staticDialog->setActiveWindow();
  62. };
  63. CSearchDialog* const CSearchDialog::getSearchDialog() {
  64. Q_ASSERT(m_staticDialog);
  65. return m_staticDialog;
  66. };
  67. CSearchDialog::CSearchDialog(TQWidget *parent)
  68. : KDialogBase(Plain, i18n("Search dialog"), Close | User1, User1, parent, "CSearchDialog", false, true, i18n("Search")) {
  69. setWFlags( getWFlags() | TQt::WStyle_MinMax );
  70. setIcon(CResMgr::searchdialog::icon);
  71. m_searcher.connectFinished( TQT_TQOBJECT(this), TQT_SLOT(searchFinished()));
  72. initView();
  73. initConnections();
  74. }
  75. CSearchDialog::~CSearchDialog(){
  76. // Added code for saving last size of dialog
  77. saveDialogSize("CSearchDialog");
  78. }
  79. /** Starts the search with the set modules and the set search text. */
  80. void CSearchDialog::startSearch() {
  81. TQString searchText(m_searchOptionsPage->searchText());
  82. if (searchText.isEmpty()) {
  83. return;
  84. }
  85. // check that we have the indices we need for searching
  86. if (!m_searcher.modulesHaveIndices( modules() ) ) {
  87. int result = TQMessageBox::question(this, i18n("Missing indices"),
  88. i18n("One or more modules need indexing before they can be searched.\n"
  89. "This could take a long time. Proceed with indexing?"),
  90. TQMessageBox::Yes | TQMessageBox::Default,
  91. TQMessageBox::No | TQMessageBox::Escape);
  92. // In SuSE 10.0 the result is the logical or of the button type, just like it is
  93. // inputed into the TQMessageBox.
  94. if ( (result == (TQMessageBox::Yes | TQMessageBox::Default)) ||
  95. (result == TQMessageBox::Yes) || (result == TQMessageBox::Default) ) {
  96. CModuleIndexDialog* dlg = CModuleIndexDialog::getInstance();
  97. dlg->indexUnindexedModules( modules() );
  98. }
  99. else {
  100. return;
  101. }
  102. }
  103. m_searchResultPage->reset();
  104. // const int searchFlags = m_searchOptionsPage->searchFlags();
  105. // const CSwordModuleSearch::scopeType scopeType = m_searchOptionsPage->scopeType();
  106. // if (scopeType == CSwordModuleSearch::Scope_LastSearch) {
  107. // searchFlags |= CSwordModuleSearch::useLastResult;
  108. // }
  109. // else if ( (scopeType == CSwordModuleSearch::Scope_Bounds)
  110. // && strlen(m_searchOptionsPage->searchScope().getRangeText())) {
  111. // //we need the scope flag and a valid scope!
  112. // searchFlags |= CSwordModuleSearch::useScope;
  113. // m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
  114. // }
  115. if (m_searchOptionsPage->hasSearchScope()) {
  116. m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
  117. }
  118. else {
  119. m_searcher.resetSearchScope();
  120. }
  121. m_searcher.setModules( modules() );
  122. m_searcher.setSearchedText(searchText);
  123. // m_searcher.setSearchOptions(searchFlags);
  124. m_searcher.startSearch();
  125. }
  126. /** Starts the search with the given module list and given search text. */
  127. void CSearchDialog::startSearch( const ListCSwordModuleInfo modules, const TQString& searchText) {
  128. m_searchResultPage->reset();
  129. m_searchOptionsPage->reset();
  130. setModules(modules);
  131. setSearchText(searchText);
  132. startSearch();
  133. }
  134. /** Returns the list of used modules. */
  135. const ListCSwordModuleInfo CSearchDialog::modules() {
  136. return m_searchOptionsPage->modules();
  137. }
  138. /** Sets the list of modules for the search. */
  139. void CSearchDialog::setModules( const ListCSwordModuleInfo modules ) {
  140. m_searchOptionsPage->setModules(modules);
  141. resize( sizeHint() );
  142. }
  143. /** Returns the search text which is set currently. */
  144. const TQString CSearchDialog::searchText() {
  145. return m_searchOptionsPage->searchText();
  146. }
  147. sword::ListKey CSearchDialog::searchScope() {
  148. return m_searchOptionsPage->searchScope();
  149. };
  150. /** Returns true if the search used a scope, otherwise false. */
  151. // const CSwordModuleSearch::scopeType CSearchDialog::searchScopeType() const {
  152. // return m_searchOptionsPage->scopeType();
  153. // }
  154. /** Returns true if the search used a scope, otherwise false. */
  155. // const int CSearchDialog::searchFlags() const {
  156. // return m_searchOptionsPage->searchFlags();
  157. // }
  158. /** Returns the search text which is used for the search. */
  159. void CSearchDialog::setSearchText( const TQString searchText ) {
  160. m_searchOptionsPage->setSearchText(searchText);
  161. }
  162. /** Initializes this object. */
  163. void CSearchDialog::initView() {
  164. setButtonTip(User1, CResMgr::searchdialog::searchButton::tooltip);
  165. TQVBoxLayout *box = new TQVBoxLayout( plainPage(), 0, spacingHint() );
  166. m_searchOptionsPage = new Options::CSearchOptionsPage(plainPage());
  167. box->addWidget( m_searchOptionsPage );
  168. m_searchResultPage = new Result::CSearchResultPage(plainPage());
  169. box->addWidget( m_searchResultPage );
  170. // The dialog doesn't resize properly if the minimum size of the
  171. // plain page is lower than the minimumsize of our two widgets.
  172. // You can resize the dialog, but it just starts covering up the
  173. // button bar and the two widgets instead of stopping at the
  174. // minimum size. The following code sets the minimum with some
  175. // margin. If you know of a better way to do this, do it!
  176. int w = m_searchOptionsPage->minimumWidth();
  177. int h = m_searchOptionsPage->minimumHeight() +
  178. m_searchResultPage->minimumHeight();
  179. plainPage()->setMinimumSize(w+10, h+100);
  180. // Added code for loading last size of dialog
  181. setInitialSize(configDialogSize("CSearchDialog"));
  182. }
  183. void CSearchDialog::searchFinished() {
  184. // tqWarning("CSearchDialog::searchFinished()");
  185. if ( m_searcher.foundItems() ) {
  186. m_searchResultPage->setSearchResult(modules());
  187. }
  188. else {
  189. m_searchResultPage->reset();
  190. }
  191. m_staticDialog->raise();
  192. m_staticDialog->setActiveWindow();
  193. }
  194. void CSearchDialog::showModulesSelector() {
  195. m_searchOptionsPage->chooseModules();
  196. }
  197. /** Initializes the signal slot connections */
  198. void CSearchDialog::initConnections() {
  199. connect(this, TQT_SIGNAL(user1Clicked()), TQT_SLOT(startSearch()));
  200. connect(this, TQT_SIGNAL(closeClicked()), TQT_SLOT(slotDelayedDestruct()));
  201. }
  202. /** Resets the parts to the default. */
  203. void CSearchDialog::reset() {
  204. m_searchOptionsPage->reset();
  205. m_searchResultPage->reset();
  206. }
  207. /** Reimplementation. */
  208. void CSearchDialog::slotClose() {
  209. delayedDestruct();
  210. m_staticDialog = 0;
  211. }
  212. } //end of namespace Search
  213. #include "csearchdialog.moc"