summaryrefslogtreecommitdiff
path: root/src/mobile/ui/btsearchinterface.h
blob: ae2e972f533edc94cf33bd96d96ba91acc1cf9b8 (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
114
115
116
117
/*********
*
* In the name of the Father, and of the Son, and of the Holy Spirit.
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2016 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License
* version 2.0.
*
**********/

#ifndef BT_SEARCH_INTERFACE_H
#define BT_SEARCH_INTERFACE_H

#include <QObject>
#include <QString>
#include "backend/cswordmodulesearch.h"
#include "mobile/models/roleitemmodel.h"
#include "mobile/models/roleitemmodel.h"
#include <listkey.h>

class CSwordKey;
class CSwordVerseKey;
class CSwordModuleInfo;
class BtModuleTextModel;
class QQuickItem;
class IndexThread;

namespace btm {

class BtSearchInterface : public QObject {

    Q_OBJECT

    enum findType {
        AndType,
        OrType,
        FullType
    };

    Q_PROPERTY(QString searchText READ getSearchText WRITE setSearchText)
    Q_PROPERTY(QString findChoice READ getFindChoice WRITE setFindChoice)
    Q_PROPERTY(QString moduleList READ getModuleList WRITE setModuleList)
    Q_PROPERTY(QVariant modulesModel READ getModulesModel NOTIFY modulesModelChanged)
    Q_PROPERTY(QVariant referencesModel READ getReferencesModel NOTIFY referencesModelChanged)
    Q_PROPERTY(int AndType READ getAndType)
    Q_PROPERTY(int OrType READ getAndType)
    Q_PROPERTY(int FullType READ getAndType)
    Q_PROPERTY(int searchType READ getSearchType WRITE setSearchType)
    Q_PROPERTY(bool indexingFinished READ getIndexingFinished NOTIFY indexingFinished)

public:
    Q_INVOKABLE bool performSearch();
    Q_INVOKABLE bool modulesAreIndexed();
    Q_INVOKABLE bool indexModules();
    Q_INVOKABLE void selectReferences(int moduleIndex);
    Q_INVOKABLE QString getModuleName(int index);
    Q_INVOKABLE QString getReference(int index);
    Q_INVOKABLE void cancel();

    BtSearchInterface(QObject *parent = nullptr);
    ~BtSearchInterface();

    QString getSearchText() const;
    QString getFindChoice() const;
    QString getModuleList() const;

    void setSearchText(const QString& searchText);
    void setFindChoice(const QString& findChoice);
    void setModuleList(const QString& moduleList);

    QVariant getModulesModel();
    QVariant getReferencesModel();

    int getAndType() { return AndType; }
    int getOrType() { return OrType; }
    int getFullType() { return FullType; }
    int getSearchType() { return m_searchType; }
    bool getIndexingFinished() {
        return true;
    };
    void setSearchType(int searchType);

signals:
    void modulesModelChanged();
    void referencesModelChanged();
    void indexingFinished();

private slots:
    void slotModuleProgress(int value);
    void slotBeginModuleIndexing(const QString& moduleName);
    void slotIndexingFinished();

private:
    QString prepareSearchText(const QString& orig);
    void setupModuleModel(const CSwordModuleSearch::Results& results);
    void setupReferenceModel(const CSwordModuleInfo *m,
                             const sword::ListKey & results);
    void setupSearchType();
    bool wasCanceled();

    int m_searchType;
    QQuickItem* m_progressObject;
    IndexThread* m_thread;
    bool m_wasCancelled;
    QString m_searchText;
    QString m_findChoice;
    QString m_moduleList;
    RoleItemModel m_modulesModel;
    RoleItemModel m_referencesModel;
    CSwordModuleSearch::Results m_results;
};

} // end namespace

#endif