summaryrefslogtreecommitdiff
path: root/src/backend/cswordmodulesearch.h
blob: bc0d37c36c414fc51ec3cbffadd29bf8a96cda62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2011 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef CSWORDMODULESEARCH_H
#define CSWORDMODULESEARCH_H

#include <QObject>

#include <QHash>

// Sword includes:
#include <listkey.h>


class CSwordModuleInfo;

/**
 * CSwordModuleSearch manages the search on Sword modules. It manages the thread(s)
 * and manages the different modules.
  *
  * @author The BibleTime team
  * @version $Id: cswordmodulesearch.h,v 1.34 2006/08/08 19:32:48 joachim Exp $
  */

class CSwordModuleSearch: public QObject {
        Q_OBJECT

    public: /* Types: */
        typedef QHash<const CSwordModuleInfo*, sword::ListKey> Results;

    public: /* Methods: */
        inline CSwordModuleSearch()
            : m_foundItems(0) {}

        /**
          Sets the text which should be search in the modules.
          \param[in] text the text to search.
        */
        inline void setSearchedText(const QString &text) {
            m_searchText = text;
        }

        /**
          Set the modules which should be searched.
          \param[in] modules the modules to search in.
        */
        inline void setModules(const QList<const CSwordModuleInfo*> &modules) {
            Q_ASSERT(!modules.empty());
            Q_ASSERT(unindexedModules(modules).empty());
            m_searchModules = modules;
        }

        /**
          Sets the search scope.
          \param[in] scope the scope used for the search.
        */
        void setSearchScope(const sword::ListKey &scope);

        /**
          Resets the search scope.
        */
        inline void resetSearchScope() {
            m_searchScope.ClearList();
        }

        /**
          \returns the search scope.
        */
        const sword::ListKey &searchScope() const {
            return m_searchScope;
        }

        /**
          Starts the search for the search text.
        */
        void startSearch();

        /**
          \returns the number of found items in the last search.
        */
        inline unsigned long foundItems() const {
            return m_foundItems;
        }

        /**
          \returns the results of the search.
        */
        const Results &results() const {
            return m_results;
        }

        /**
          \returns the list of unindexed modules in the given list.
        */
        static QList<const CSwordModuleInfo*> unindexedModules(
                const QList<const CSwordModuleInfo*> &modules);

    private: /* Fields: */
        QString                        m_searchText;
        sword::ListKey                 m_searchScope;
        QList<const CSwordModuleInfo*> m_searchModules;

        Results                        m_results;
        unsigned long                  m_foundItems;
};

#endif