summaryrefslogtreecommitdiff
path: root/src/bibletime_dbus.cpp
blob: 6beb7fdd69d19b1c9c72a049234557e4520513d4 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2014 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#include "bibletime.h"

#include <QList>
#include <QMdiSubWindow>
#include "backend/keys/cswordversekey.h"
#include "frontend/cmdiarea.h"

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


//helper function
void BibleTime::syncAllModulesByType(const CSwordModuleInfo::ModuleType type, const QString& key) {
    Q_FOREACH (const QMdiSubWindow * const w, m_mdi->usableWindowList()) {
        CDisplayWindow * const d = dynamic_cast<CDisplayWindow*>(w->widget());
        if (d != 0 && !d->modules().isEmpty() && d->modules().first()->type() == type) {
            d->lookupKey(key);
        }
    }
}

void BibleTime::closeAllModuleWindows() {
    m_mdi->closeAllSubWindows();
}
QStringList BibleTime::searchInModule(const QString& moduleName, const QString& searchText) {
    QStringList ret;
    CSwordModuleInfo* mod = CSwordBackend::instance()->findModuleByName(moduleName);

    if (mod) {
        sword::ListKey result;

        //mod->search(searchText, CSwordModuleSearch::multipleWords, sword::ListKey());
        sword::ListKey scope;
        mod->searchIndexed(searchText, scope, result);

        const QString lead = QString("[%1] ").arg(moduleName);

        for (int i = 0; i < result.getCount(); i++) {
            sword::SWKey* key = result.getElement(i);
            Q_ASSERT(key);


            if (mod->type() == CSwordModuleInfo::Bible || mod->type() == CSwordModuleInfo::Commentary) {
                sword::VerseKey vk(key->getText());
                ret << lead + QString::fromUtf8( vk.getOSISRef() );
            }
            else {
                ret << lead + QString::fromUtf8( key->getText() );
            }
        }
    }
    return ret;
}

QStringList BibleTime::searchInOpenModules(const QString& searchText) {
    QStringList ret;
    Q_FOREACH (const QMdiSubWindow * const subWindow, m_mdi->subWindowList()) {
        const CDisplayWindow * const w = dynamic_cast<CDisplayWindow*>(subWindow->widget());
        if (w != 0) {
            Q_FOREACH (const CSwordModuleInfo * const mi, w->modules()) {
                ret += searchInModule(mi->name(), searchText);
            }
        }
    }
    return ret;
}

QString BibleTime::getCurrentReference() {
    QString ret = QString::null;

    QMdiSubWindow* activeSubWindow = m_mdi->activeSubWindow();
    if (!activeSubWindow) return ret;

    CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(activeSubWindow->widget());

    if (w) {
        QString modType;
        Q_ASSERT(w->modules().first());
        switch (w->modules().first()->type()) {
            case CSwordModuleInfo::Bible:
                modType = "BIBLE";
                break;
            case CSwordModuleInfo::Commentary:
                modType = "COMMENTARY";
                break;
            case CSwordModuleInfo::GenericBook:
                modType = "BOOK";
                break;
            case CSwordModuleInfo::Lexicon:
                modType = "LEXICON";
                break;
            default:
                modType = "UNSUPPORTED";
                break;
        }

        ret.append("[").append(w->modules().first()->name()).append("] ");
        ret.append("[").append(modType).append("] ");

        CSwordVerseKey* vk = dynamic_cast<CSwordVerseKey*>( w->key() );
        if (vk) {
            ret.append( vk->getOSISRef() );
        }
        else {
            ret.append( w->key()->key() );
        }
    }

    return ret;
}

QStringList BibleTime::getModulesOfType(const QString& type) {
    QStringList ret;
    CSwordModuleInfo::ModuleType modType;

    if (type == "BIBLES") {
        modType = CSwordModuleInfo::Bible;
    }
    else if (type == "COMMENTARIES") {
        modType = CSwordModuleInfo::Commentary;
    }
    else if (type == "LEXICONS") {
        modType = CSwordModuleInfo::Lexicon;
    }
    else if (type == "BOOKS") {
        modType = CSwordModuleInfo::GenericBook;
    }
    else {
        modType = CSwordModuleInfo::Unknown;
    }

    Q_FOREACH(const CSwordModuleInfo * const mi, CSwordBackend::instance()->moduleList()) {
        if (mi->type() == modType) {
            ret.append(mi->name());
        }
    }

    return ret;
}