~ubuntu-branches/ubuntu/trusty/bibletime/trusty

« back to all changes in this revision

Viewing changes to src/backend/cswordmodulesearch.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Marsden
  • Date: 2009-11-18 17:30:00 UTC
  • mfrom: (1.3.4 upstream) (5.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091118173000-endkhjz5qai88tvr
Tags: 2.4-1
* New upstream version 2.4
* debian/control: 
  - Replace incorrect bibletime-data Depends on lib4qt-gui
    with bibletime Depends on libqtgui4 (>= 4.4.0). (Closes: #556209).
  - Add Build-depends: on zlib1g-dev and libcurl4-gnutls-dev 
    (Closes: #556805).

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
*
8
8
**********/
9
9
 
10
 
//BibleTime includes
11
 
#include "cswordmodulesearch.h"
 
10
#include "backend/cswordmodulesearch.h"
12
11
 
 
12
#include "backend/config/cbtconfig.h"
13
13
#include "backend/drivers/cswordmoduleinfo.h"
14
14
#include "backend/managers/cswordbackend.h"
15
 
#include "backend/config/cbtconfig.h"
16
15
 
17
 
//Sword includes
 
16
// Sword includes:
 
17
#include <listkey.h>
 
18
#include <swkey.h>
18
19
#include <swmodule.h>
19
 
#include <swkey.h>
20
 
#include <listkey.h>
21
20
 
22
21
 
23
22
CSwordModuleSearch* CSwordModuleSearch::searcher = 0;
24
23
 
25
24
CSwordModuleSearch::CSwordModuleSearch()
26
 
        : m_searchedText(QString::null),
27
 
        m_searchOptions(0),
28
 
        m_foundItems(false)
29
 
{
30
 
        searcher = this;
 
25
        : m_searchedText(QString::null),
 
26
        m_searchOptions(0),
 
27
        m_foundItems(false) {
 
28
    searcher = this;
31
29
}
32
30
 
33
31
CSwordModuleSearch::~CSwordModuleSearch() {
34
 
        searcher = 0;
 
32
    searcher = 0;
35
33
}
36
34
 
37
35
/** This function sets the modules which should be searched. */
38
36
void CSwordModuleSearch::setModules( const QList<CSwordModuleInfo*>& list ) {
39
 
        m_moduleList = list;
 
37
    m_moduleList = list;
40
38
}
41
39
 
42
40
/** Starts the search for the search text. */
43
41
bool CSwordModuleSearch::startSearch() {
44
 
        backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
45
 
        m_foundItems   = false;
46
 
 
47
 
        bool foundItems = false;
48
 
 
49
 
        // for (m_moduleList.first(); m_moduleList.current() && !m_terminateSearch; m_moduleList.next()) {
50
 
        QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
51
 
 
52
 
        for (QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin(); it != end_it; ++it) {
53
 
                if ( (*it)->searchIndexed(m_searchedText/*, m_searchOptions*/, m_searchScope) ) {
54
 
                        foundItems = true;
55
 
                }
56
 
        }
57
 
 
58
 
        m_foundItems = foundItems;
59
 
 
60
 
        //m_finishedSig.activate();
61
 
        emit finished();
62
 
        return true;
 
42
    backend()->setFilterOptions ( CBTConfig::getFilterOptionDefaults() );
 
43
    m_foundItems   = false;
 
44
 
 
45
    bool foundItems = false;
 
46
 
 
47
    // for (m_moduleList.first(); m_moduleList.current() && !m_terminateSearch; m_moduleList.next()) {
 
48
    QList<CSwordModuleInfo*>::iterator end_it = m_moduleList.end();
 
49
 
 
50
    for (QList<CSwordModuleInfo*>::iterator it = m_moduleList.begin(); it != end_it; ++it) {
 
51
        if ( (*it)->searchIndexed(m_searchedText/*, m_searchOptions*/, m_searchScope) ) {
 
52
            foundItems = true;
 
53
        }
 
54
    }
 
55
 
 
56
    m_foundItems = foundItems;
 
57
 
 
58
    //m_finishedSig.activate();
 
59
    emit finished();
 
60
    return true;
63
61
}
64
62
 
65
63
/** Sets the text which should be search in the modules. */
66
64
void CSwordModuleSearch::setSearchedText( const QString& text ) {
67
 
        m_searchedText = text;
 
65
    m_searchedText = text;
68
66
}
69
67
 
70
68
/** Sets the search scope. */
71
69
void CSwordModuleSearch::setSearchScope( const sword::ListKey& scope ) {
72
 
        m_searchScope.copyFrom( scope );
73
 
 
74
 
        if (!strlen(scope.getRangeText())) { //we can't search with an empty search scope, would crash
75
 
                //reset the scope
76
 
                resetSearchScope();
77
 
 
78
 
                //disable searching with a scope!
79
 
                //  if (m_searchOptions | useScope) {
80
 
                //      qWarning("using the scope!");
81
 
                //set back the scope flag
82
 
                // }
83
 
        }
 
70
    m_searchScope.copyFrom( scope );
 
71
 
 
72
    if (!strlen(scope.getRangeText())) { //we can't search with an empty search scope, would crash
 
73
        //reset the scope
 
74
        resetSearchScope();
 
75
 
 
76
        //disable searching with a scope!
 
77
        //  if (m_searchOptions | useScope) {
 
78
        //      qWarning("using the scope!");
 
79
        //set back the scope flag
 
80
        // }
 
81
    }
84
82
}
85
83
 
86
84
/** Sets the search scope back. */
87
85
void CSwordModuleSearch::resetSearchScope() {
88
 
        m_searchScope.ClearList();
 
86
    m_searchScope.ClearList();
89
87
}
90
88
 
91
89
/** Returns true if in the last search the searcher found items, if no items were found return false. */
92
90
bool CSwordModuleSearch::foundItems() const {
93
 
        return m_foundItems;
 
91
    return m_foundItems;
94
92
}
95
93
 
96
94
/** Returns a copy of the used search scope. */
97
95
const sword::ListKey& CSwordModuleSearch::searchScope() const {
98
 
        return m_searchScope;
 
96
    return m_searchScope;
99
97
}
100
98
 
101
99
void CSwordModuleSearch::connectFinished( QObject *receiver, const char *member ) {
102
 
        //m_finishedSig.connect(receiver, member);
103
 
        QObject::connect(this, SIGNAL(finished()), receiver, member);
104
 
}
105
 
 
106
 
/** Should be called when the search finished. */
107
 
void CSwordModuleSearch::searchFinished() {
108
 
        //m_finishedSig.activate();
109
 
        emit finished();
110
 
}
111
 
 
112
 
bool CSwordModuleSearch::modulesHaveIndices( const QList<CSwordModuleInfo*>& modules )
113
 
{
114
 
        bool hasIndices = true;
115
 
        QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
116
 
        for( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
117
 
                if (!(*it)->hasIndex()) {
118
 
                        hasIndices = false;
119
 
                        break;
120
 
                }
121
 
        }
122
 
        return hasIndices;
 
100
    //m_finishedSig.connect(receiver, member);
 
101
    QObject::connect(this, SIGNAL(finished()), receiver, member);
 
102
}
 
103
 
 
104
bool CSwordModuleSearch::modulesHaveIndices( const QList<CSwordModuleInfo*>& modules ) {
 
105
    bool hasIndices = true;
 
106
    QList<CSwordModuleInfo*>::const_iterator end_it = modules.end();
 
107
    for ( QList<CSwordModuleInfo*>::const_iterator it = modules.begin(); it != end_it; ++it) {
 
108
        if (!(*it)->hasIndex()) {
 
109
            hasIndices = false;
 
110
            break;
 
111
        }
 
112
    }
 
113
    return hasIndices;
123
114
}