3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
5
* Copyright 1999-2006 by the BibleTime developers.
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
12
#include "csearchdialog.h"
13
#include "csearchanalysis.h"
14
#include "backend/cswordmodulesearch.h"
17
#include "backend/cswordkey.h"
18
#include "backend/cswordversekey.h"
20
#include "frontend/cbtconfig.h"
21
#include "frontend/cmoduleindexdialog.h"
23
#include "util/cresmgr.h"
24
#include "util/ctoolclass.h"
33
#include <qlineedit.h>
34
#include <qtextedit.h>
36
#include <qsizepolicy.h>
37
#include <qpushbutton.h>
40
#include <qmessagebox.h>
43
#include <kapplication.h>
44
#include <kfiledialog.h>
46
#include <kiconloader.h>
50
static CSearchDialog* m_staticDialog = 0;
52
void CSearchDialog::openDialog(const ListCSwordModuleInfo modules, const QString& searchText, QWidget* parentDialog) {
53
if (!m_staticDialog) {
54
m_staticDialog = new CSearchDialog(parentDialog);
56
m_staticDialog->reset();
58
if (modules.count()) {
59
m_staticDialog->setModules(modules);
62
m_staticDialog->showModulesSelector();
65
m_staticDialog->setSearchText(searchText);
66
if (m_staticDialog->isHidden()) {
67
m_staticDialog->show();
70
if (modules.count() && !searchText.isEmpty()) {
71
m_staticDialog->startSearch();
73
// moved these to after the startSearch() because
74
// the progress dialog caused them to loose focus.
75
m_staticDialog->raise();
76
m_staticDialog->setActiveWindow();
79
CSearchDialog* const CSearchDialog::getSearchDialog() {
80
Q_ASSERT(m_staticDialog);
81
return m_staticDialog;
84
CSearchDialog::CSearchDialog(QWidget *parent)
85
: KDialogBase(Plain, i18n("Search dialog"), Close | User1, User1, parent, "CSearchDialog", false, true, i18n("Search")) {
87
setWFlags( getWFlags() | Qt::WStyle_MinMax );
88
setIcon(CResMgr::searchdialog::icon);
90
m_searcher.connectFinished( this, SLOT(searchFinished()));
96
CSearchDialog::~CSearchDialog(){
97
// Added code for saving last size of dialog
98
saveDialogSize("CSearchDialog");
101
/** Starts the search with the set modules and the set search text. */
102
void CSearchDialog::startSearch() {
103
QString searchText(m_searchOptionsPage->searchText());
105
if (searchText.isEmpty()) {
109
// check that we have the indices we need for searching
110
if (!m_searcher.modulesHaveIndices( modules() ) ) {
111
int result = QMessageBox::question(this, i18n("Missing indices"),
112
i18n("One or more modules need indexing before they can be searched.\n"
113
"This could take a long time. Proceed with indexing?"),
114
QMessageBox::Yes | QMessageBox::Default,
115
QMessageBox::No | QMessageBox::Escape);
116
// In SuSE 10.0 the result is the logical or of the button type, just like it is
117
// inputed into the QMessageBox.
118
if ( (result == (QMessageBox::Yes | QMessageBox::Default)) ||
119
(result == QMessageBox::Yes) || (result == QMessageBox::Default) ) {
120
CModuleIndexDialog* dlg = CModuleIndexDialog::getInstance();
121
dlg->indexUnindexedModules( modules() );
128
m_searchResultPage->reset();
130
// const int searchFlags = m_searchOptionsPage->searchFlags();
132
// const CSwordModuleSearch::scopeType scopeType = m_searchOptionsPage->scopeType();
133
// if (scopeType == CSwordModuleSearch::Scope_LastSearch) {
134
// searchFlags |= CSwordModuleSearch::useLastResult;
136
// else if ( (scopeType == CSwordModuleSearch::Scope_Bounds)
137
// && strlen(m_searchOptionsPage->searchScope().getRangeText())) {
138
// //we need the scope flag and a valid scope!
139
// searchFlags |= CSwordModuleSearch::useScope;
140
// m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
143
if (m_searchOptionsPage->hasSearchScope()) {
144
m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
147
m_searcher.resetSearchScope();
150
m_searcher.setModules( modules() );
151
m_searcher.setSearchedText(searchText);
152
// m_searcher.setSearchOptions(searchFlags);
154
m_searcher.startSearch();
157
/** Starts the search with the given module list and given search text. */
158
void CSearchDialog::startSearch( const ListCSwordModuleInfo modules, const QString& searchText) {
159
m_searchResultPage->reset();
160
m_searchOptionsPage->reset();
162
setSearchText(searchText);
167
/** Returns the list of used modules. */
168
const ListCSwordModuleInfo CSearchDialog::modules() {
169
return m_searchOptionsPage->modules();
172
/** Sets the list of modules for the search. */
173
void CSearchDialog::setModules( const ListCSwordModuleInfo modules ) {
174
m_searchOptionsPage->setModules(modules);
175
resize( sizeHint() );
178
/** Returns the search text which is set currently. */
179
const QString CSearchDialog::searchText() {
180
return m_searchOptionsPage->searchText();
183
sword::ListKey CSearchDialog::searchScope() {
184
return m_searchOptionsPage->searchScope();
187
/** Returns true if the search used a scope, otherwise false. */
188
// const CSwordModuleSearch::scopeType CSearchDialog::searchScopeType() const {
189
// return m_searchOptionsPage->scopeType();
192
/** Returns true if the search used a scope, otherwise false. */
193
// const int CSearchDialog::searchFlags() const {
194
// return m_searchOptionsPage->searchFlags();
197
/** Returns the search text which is used for the search. */
198
void CSearchDialog::setSearchText( const QString searchText ) {
199
m_searchOptionsPage->setSearchText(searchText);
202
/** Initializes this object. */
203
void CSearchDialog::initView() {
204
setButtonTip(User1, CResMgr::searchdialog::searchButton::tooltip);
206
QVBoxLayout *box = new QVBoxLayout( plainPage(), 0, spacingHint() );
208
m_searchOptionsPage = new Options::CSearchOptionsPage(plainPage());
209
box->addWidget( m_searchOptionsPage );
211
m_searchResultPage = new Result::CSearchResultPage(plainPage());
212
box->addWidget( m_searchResultPage );
214
// The dialog doesn't resize properly if the minimum size of the
215
// plain page is lower than the minimumsize of our two widgets.
216
// You can resize the dialog, but it just starts covering up the
217
// button bar and the two widgets instead of stopping at the
218
// minimum size. The following code sets the minimum with some
219
// margin. If you know of a better way to do this, do it!
220
int w = m_searchOptionsPage->minimumWidth();
221
int h = m_searchOptionsPage->minimumHeight() +
222
m_searchResultPage->minimumHeight();
223
plainPage()->setMinimumSize(w+10, h+100);
224
// Added code for loading last size of dialog
225
setInitialSize(configDialogSize("CSearchDialog"));
228
void CSearchDialog::searchFinished() {
229
// qWarning("CSearchDialog::searchFinished()");
231
if ( m_searcher.foundItems() ) {
232
m_searchResultPage->setSearchResult(modules());
235
m_searchResultPage->reset();
237
m_staticDialog->raise();
238
m_staticDialog->setActiveWindow();
241
void CSearchDialog::showModulesSelector() {
242
m_searchOptionsPage->chooseModules();
245
/** Initializes the signal slot connections */
246
void CSearchDialog::initConnections() {
247
connect(this, SIGNAL(user1Clicked()), SLOT(startSearch()));
248
connect(this, SIGNAL(closeClicked()), SLOT(slotDelayedDestruct()));
251
/** Resets the parts to the default. */
252
void CSearchDialog::reset() {
253
m_searchOptionsPage->reset();
254
m_searchResultPage->reset();
257
/** Reimplementation. */
258
void CSearchDialog::slotClose() {
263
} //end of namespace Search