diff options
Diffstat (limited to 'src/backend/cswordmodulesearch.cpp')
-rw-r--r-- | src/backend/cswordmodulesearch.cpp | 101 |
1 files changed, 25 insertions, 76 deletions
diff --git a/src/backend/cswordmodulesearch.cpp b/src/backend/cswordmodulesearch.cpp index 9348295..694151d 100644 --- a/src/backend/cswordmodulesearch.cpp +++ b/src/backend/cswordmodulesearch.cpp @@ -2,7 +2,7 @@ * * This file is part of BibleTime's source code, http://www.bibletime.info/. * -* Copyright 1999-2008 by the BibleTime developers. +* Copyright 1999-2011 by the BibleTime developers. * The BibleTime source code is licensed under the GNU General Public License version 2.0. * **********/ @@ -10,63 +10,32 @@ #include "backend/cswordmodulesearch.h" #include "backend/config/cbtconfig.h" -#include "backend/drivers/cswordmoduleinfo.h" #include "backend/managers/cswordbackend.h" +#include "btglobal.h" -// Sword includes: -#include <listkey.h> -#include <swkey.h> -#include <swmodule.h> +void CSwordModuleSearch::startSearch() { + // Clear old search results: + m_results.clear(); + m_foundItems = 0; -CSwordModuleSearch* CSwordModuleSearch::searcher = 0; + /// \todo What is the purpose of the following statement? + CSwordBackend::instance()->setFilterOptions(CBTConfig::getFilterOptionDefaults()); -CSwordModuleSearch::CSwordModuleSearch() - : m_searchedText(QString::null), - m_searchOptions(0), - m_foundItems(false) { - searcher = this; -} - -CSwordModuleSearch::~CSwordModuleSearch() { - searcher = 0; -} - -/** This function sets the modules which should be searched. */ -void CSwordModuleSearch::setModules( const QList<CSwordModuleInfo*>& list ) { - m_moduleList = list; -} - -/** Starts the search for the search text. */ -bool CSwordModuleSearch::startSearch() { - backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() ); - m_foundItems = false; - - bool foundItems = false; - - // for (m_moduleList.first(); m_moduleList.current() && !m_terminateSearch; m_moduleList.next()) { - QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end(); - - for (QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin(); it != end_it; ++it) { - if ( (*it)->searchIndexed(m_searchedText/*, m_searchOptions*/, m_searchScope) ) { - foundItems = true; + // Search module-by-module: + Q_FOREACH(const CSwordModuleInfo *m, m_searchModules) { + sword::ListKey results; + int found = m->searchIndexed(m_searchText, m_searchScope, results); + if (found > 0) { + m_results.insert(m, results); + m_foundItems += found; } } - - m_foundItems = foundItems; - - //m_finishedSig.activate(); - emit finished(); - return true; } -/** Sets the text which should be search in the modules. */ -void CSwordModuleSearch::setSearchedText( const QString& text ) { - m_searchedText = text; -} +void CSwordModuleSearch::setSearchScope(const sword::ListKey &scope) { + /// \todo Properly examine and document the inner workings of this method. -/** Sets the search scope. */ -void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) { m_searchScope.copyFrom( scope ); if (!strlen(scope.getRangeText())) { //we can't search with an empty search scope, would crash @@ -81,34 +50,14 @@ void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) { } } -/** Sets the search scope back. */ -void CSwordModuleSearch::resetSearchScope() { - m_searchScope.ClearList(); -} - -/** Returns true if in the last search the searcher found items, if no items were found return false. */ -bool CSwordModuleSearch::foundItems() const { - return m_foundItems; -} - -/** Returns a copy of the used search scope. */ -const sword::ListKey& CSwordModuleSearch::searchScope() const { - return m_searchScope; -} - -void CSwordModuleSearch::connectFinished( QObject *receiver, const char *member ) { - //m_finishedSig.connect(receiver, member); - QObject::connect(this, SIGNAL(finished()), receiver, member); -} - -bool CSwordModuleSearch::modulesHaveIndices( const QList<CSwordModuleInfo*>& modules ) { - bool hasIndices = true; - QList<CSwordModuleInfo*>::const_iterator end_it = modules.end(); - for ( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) { - if (!(*it)->hasIndex()) { - hasIndices = false; - break; +QList<const CSwordModuleInfo*> CSwordModuleSearch::unindexedModules( + const QList<const CSwordModuleInfo*> &modules) +{ + QList<const CSwordModuleInfo*> unindexed; + Q_FOREACH (const CSwordModuleInfo *m, modules) { + if (!m->hasIndex()) { + unindexed.append(m); } } - return hasIndices; + return unindexed; } |