~ubuntu-branches/ubuntu/jaunty/bibletime/jaunty

« back to all changes in this revision

Viewing changes to bibletime/frontend/searchdialog/csearchdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ralph Janke
  • Date: 2008-05-10 15:18:16 UTC
  • mfrom: (1.1.6 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080510151816-bqp8y1to705zd0fm
Tags: 1.6.5.1-1
* New upstream version (Closes: #441161, #271502)
* fixes for new autotools and gcc 4.3 (Closes: #407291)
* added poxml to Build-Depends
* No DFSG necessary anymore since biblestudy howto has 
  now Commons Licence 
* Added libclucene-dev to dev-depends (Closes: #436677)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
10
 
 
11
 
 
12
#include "csearchdialog.h"
 
13
#include "csearchanalysis.h"
 
14
#include "backend/cswordmodulesearch.h"
 
15
 
 
16
 
 
17
#include "backend/cswordkey.h"
 
18
#include "backend/cswordversekey.h"
 
19
 
 
20
#include "frontend/cbtconfig.h"
 
21
#include "frontend/cmoduleindexdialog.h"
 
22
 
 
23
#include "util/cresmgr.h"
 
24
#include "util/ctoolclass.h"
 
25
 
 
26
//Qt includes
 
27
#include <qhbox.h>
 
28
#include <qvbox.h>
 
29
#include <qptrlist.h>
 
30
#include <qpainter.h>
 
31
#include <qlayout.h>
 
32
#include <qmap.h>
 
33
#include <qlineedit.h>
 
34
#include <qtextedit.h>
 
35
#include <qlabel.h>
 
36
#include <qsizepolicy.h>
 
37
#include <qpushbutton.h>
 
38
#include <qheader.h>
 
39
#include <qregexp.h>
 
40
#include <qmessagebox.h>
 
41
 
 
42
//KDE includes
 
43
#include <kapplication.h>
 
44
#include <kfiledialog.h>
 
45
#include <klocale.h>
 
46
#include <kiconloader.h>
 
47
 
 
48
namespace Search {
 
49
 
 
50
static CSearchDialog* m_staticDialog = 0;
 
51
 
 
52
void CSearchDialog::openDialog(const ListCSwordModuleInfo modules, const QString& searchText, QWidget* parentDialog) {
 
53
        if (!m_staticDialog) {
 
54
                m_staticDialog = new CSearchDialog(parentDialog);
 
55
        };
 
56
        m_staticDialog->reset();
 
57
 
 
58
        if (modules.count()) {
 
59
                m_staticDialog->setModules(modules);
 
60
        }
 
61
        else {
 
62
                m_staticDialog->showModulesSelector();
 
63
        }
 
64
 
 
65
        m_staticDialog->setSearchText(searchText);
 
66
        if (m_staticDialog->isHidden()) {
 
67
                m_staticDialog->show();
 
68
        }
 
69
 
 
70
        if (modules.count() && !searchText.isEmpty()) {
 
71
                m_staticDialog->startSearch();
 
72
        }
 
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();
 
77
};
 
78
 
 
79
CSearchDialog* const CSearchDialog::getSearchDialog() {
 
80
        Q_ASSERT(m_staticDialog);
 
81
        return m_staticDialog;
 
82
};
 
83
 
 
84
CSearchDialog::CSearchDialog(QWidget *parent)
 
85
: KDialogBase(Plain, i18n("Search dialog"), Close | User1, User1, parent, "CSearchDialog", false, true, i18n("Search")) {
 
86
 
 
87
        setWFlags( getWFlags() | Qt::WStyle_MinMax );
 
88
        setIcon(CResMgr::searchdialog::icon);
 
89
 
 
90
        m_searcher.connectFinished( this, SLOT(searchFinished()));
 
91
 
 
92
        initView();
 
93
        initConnections();
 
94
}
 
95
 
 
96
CSearchDialog::~CSearchDialog(){
 
97
        // Added code for saving last size of dialog
 
98
        saveDialogSize("CSearchDialog");
 
99
}
 
100
 
 
101
/** Starts the search with the set modules and the set search text. */
 
102
void CSearchDialog::startSearch() {
 
103
        QString searchText(m_searchOptionsPage->searchText());
 
104
 
 
105
        if (searchText.isEmpty()) {
 
106
                return;
 
107
        }
 
108
 
 
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() );
 
122
                }
 
123
                else {
 
124
                        return;
 
125
                }
 
126
        }
 
127
 
 
128
        m_searchResultPage->reset();
 
129
 
 
130
//      const int searchFlags = m_searchOptionsPage->searchFlags();
 
131
 
 
132
//      const CSwordModuleSearch::scopeType scopeType = m_searchOptionsPage->scopeType();
 
133
//      if (scopeType == CSwordModuleSearch::Scope_LastSearch) {
 
134
//              searchFlags |= CSwordModuleSearch::useLastResult;
 
135
//      }
 
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() );
 
141
//      }
 
142
 
 
143
        if (m_searchOptionsPage->hasSearchScope()) {
 
144
                m_searcher.setSearchScope( m_searchOptionsPage->searchScope() );
 
145
        }
 
146
        else {
 
147
                m_searcher.resetSearchScope();
 
148
        }
 
149
 
 
150
        m_searcher.setModules( modules() );
 
151
        m_searcher.setSearchedText(searchText);
 
152
//      m_searcher.setSearchOptions(searchFlags);
 
153
 
 
154
        m_searcher.startSearch();
 
155
}
 
156
 
 
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();
 
161
        setModules(modules);
 
162
        setSearchText(searchText);
 
163
 
 
164
        startSearch();
 
165
}
 
166
 
 
167
/** Returns the list of used modules. */
 
168
const ListCSwordModuleInfo CSearchDialog::modules() {
 
169
        return m_searchOptionsPage->modules();
 
170
}
 
171
 
 
172
/** Sets the list of modules for the search. */
 
173
void CSearchDialog::setModules( const ListCSwordModuleInfo modules ) {
 
174
        m_searchOptionsPage->setModules(modules);
 
175
        resize( sizeHint() );
 
176
}
 
177
 
 
178
/** Returns the search text which is set currently. */
 
179
const QString CSearchDialog::searchText() {
 
180
        return m_searchOptionsPage->searchText();
 
181
}
 
182
 
 
183
sword::ListKey CSearchDialog::searchScope() {
 
184
        return m_searchOptionsPage->searchScope();
 
185
};
 
186
 
 
187
/** Returns true if the search used a scope, otherwise false. */
 
188
// const CSwordModuleSearch::scopeType CSearchDialog::searchScopeType() const {
 
189
//      return m_searchOptionsPage->scopeType();
 
190
// }
 
191
 
 
192
/** Returns true if the search used a scope, otherwise false. */
 
193
// const int CSearchDialog::searchFlags() const {
 
194
//      return m_searchOptionsPage->searchFlags();
 
195
// }
 
196
 
 
197
/** Returns the search text which is used for the search. */
 
198
void CSearchDialog::setSearchText( const QString searchText ) {
 
199
        m_searchOptionsPage->setSearchText(searchText);
 
200
}
 
201
 
 
202
/** Initializes this object. */
 
203
void CSearchDialog::initView() {
 
204
        setButtonTip(User1, CResMgr::searchdialog::searchButton::tooltip);
 
205
 
 
206
   QVBoxLayout *box = new QVBoxLayout( plainPage(), 0, spacingHint() );
 
207
 
 
208
   m_searchOptionsPage = new Options::CSearchOptionsPage(plainPage());
 
209
        box->addWidget( m_searchOptionsPage );
 
210
 
 
211
        m_searchResultPage = new Result::CSearchResultPage(plainPage());
 
212
        box->addWidget( m_searchResultPage );
 
213
 
 
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"));
 
226
}
 
227
 
 
228
void CSearchDialog::searchFinished() {
 
229
//      qWarning("CSearchDialog::searchFinished()");
 
230
 
 
231
        if ( m_searcher.foundItems() ) {
 
232
                m_searchResultPage->setSearchResult(modules());
 
233
        }
 
234
        else {
 
235
                m_searchResultPage->reset();
 
236
        }
 
237
        m_staticDialog->raise();
 
238
        m_staticDialog->setActiveWindow();
 
239
}
 
240
 
 
241
void CSearchDialog::showModulesSelector() {
 
242
        m_searchOptionsPage->chooseModules();
 
243
}
 
244
 
 
245
/** Initializes the signal slot connections */
 
246
void CSearchDialog::initConnections() {
 
247
        connect(this, SIGNAL(user1Clicked()), SLOT(startSearch()));
 
248
        connect(this, SIGNAL(closeClicked()), SLOT(slotDelayedDestruct()));
 
249
}
 
250
 
 
251
/** Resets the parts to the default. */
 
252
void CSearchDialog::reset() {
 
253
        m_searchOptionsPage->reset();
 
254
        m_searchResultPage->reset();
 
255
}
 
256
 
 
257
/** Reimplementation. */
 
258
void CSearchDialog::slotClose() {
 
259
        delayedDestruct();
 
260
        m_staticDialog = 0;
 
261
}
 
262
 
 
263
} //end of namespace Search