summaryrefslogtreecommitdiff
path: root/src/backend/drivers/cswordmoduleinfo.h
blob: 9f32b12f346d42afa4ec099fb10532d9775978e9 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2008 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/

#ifndef CSWORDMODULEINFO_H
#define CSWORDMODULEINFO_H

#include "backend/managers/clanguagemgr.h"

#include <QList>
#include <QMetaType>
#include <QString>

// Sword includes:
#include <listkey.h>
#include <swdisp.h>
#include <swmodule.h>
#include <swsearchable.h>
#include <swversion.h>


class CSwordBackend;
class CSwordKey;

namespace Rendering {

class CEntryDisplay;
}

/**
 * Base class for Sword modules.
 * This is the base class for all Sword modules. Every class handling a special Sword module type
 * does inherit from this class.
 *
 * @author The BibleTime team
 * @version $Id: cswordmoduleinfo.h,v 1.83 2007/02/04 23:12:32 joachim Exp $
 */

class CSwordModuleInfo: public QObject {
        Q_OBJECT

    public:
        /**
         * These are the options which could be supported by modules and by this backend.
         * It's used in @ref CSwordBackend::setOption.
         */
        enum FilterTypes {
            footnotes, /**< Footnotes embedded in the module's text */
            strongNumbers, /**< strong numbers, usually in the text for the info display */
            headings, /**< additional section headings */
            morphTags, /**< morphology */
            lemmas, /**< lemma tags */
            hebrewPoints,/**< Hebrew vowel points */
            hebrewCantillation, /**<Hewbrew caantillation points */
            greekAccents, /**< Greek accents may be switched on and off */
            scriptureReferences, /**< scripture references may be switched on and off, just makes sense in Bibles */
            redLetterWords, /**< Jesus words in red, color is template specific */
            textualVariants, /**< variants */
            morphSegmentation, /**< morph word segmentation, supported by OSIS */
            filterTypesMIN = footnotes, /**< first entry of this enum */
            filterTypesMAX = morphSegmentation /**< last item in this enum */
            //     transliteration /* The following are handled in a special way */
        };
        /** The text direction of a module */
        enum TextDirection { /* The text direction of the modules's text */
            LeftToRight, /**< Left to right text direction, the default setting */
            RightToLeft /**< Right to left text directin, e.g. for hebrew */
        };
        /** The module type.
        */
        enum ModuleType {
            Bible, /**< Bible module */
            Commentary, /**< Commentary module */
            Lexicon, /**< Lexicon module */
            GenericBook, /**< Generic book module */
            Unknown /**< Fall back type for unknown modules */
        };
        /**
         * This enum is used to give
         * back an error code after unlocking the module
         * BibleTime stores the unlock key not in the module's config file but in BibleTime's
         * configuration file.
         */
        enum UnlockErrorCode {
            noError, /**< No error occured, everything worked ok. The key was written to the BibleTime config */
            wrongUnlockKey, /**< The wrong key was used. Module is not unlocked */
            notLocked, /**< The module was not locked so it can't be unlocked */
            noPermission /**< The key was not written to config because we have no permissions */
        };
        enum ConfigEntry {
            AboutInformation, /**< The about information of a module which is stored in the config file*/
            AbsoluteDataPath, /**< The absolute data path stored in the config object */
            CipherKey, /**< The cipher key which was used to unlock the module. Not necessarily set.*/
            DataPath, /**< The relative path. See AbsoluteDataPath*/
            Description, /**< The module description stored in the config file */
            ModuleVersion, /**< The module's version.*/
            MinimumSwordVersion, /**< The required Sword Version of this module. Otherwise some things may not work (compression etc.).*/
            TextDir, /**< The text direction */
            DisplayLevel, /**< Mostly used for books. Gives the level which should contain the connected entries.*/
            GlossaryFrom, /**< lamguage from which the Glosaary tramslates */
            GlossaryTo, /**< lamguages to which the glossary maps to */
            DistributionLicense,
            DistributionSource,
            DistributionNotes,
            TextSource,
            CopyrightNotes,
            CopyrightHolder,
            CopyrightDate,
            CopyrightContactName,
            CopyrightContactAddress,
            CopyrightContactEmail,
            Markup  /**< The markup of this module */
        };
        enum Feature {
            //StrongsNumbers, /**< Use for Bibles which have embedded strong numbers */ BT does not use this as a user option
            GreekDef,
            HebrewDef,
            GreekParse,
            HebrewParse,
            featureMin = GreekDef,
            featureMax = HebrewParse
        };
        enum Category {
            UnknownCategory = 0x0,  /**< Unknown or unset category. */
            NoCategory      = 0x0,
            Bibles          = 0x01,
            Commentaries    = 0x02,
            Books           = 0x04,
            Lexicons        = 0x08,
            Glossary        = 0x10,
            DailyDevotional = 0x20,
            Images          = 0x40,
            Cult            = 0x80, /**< Cult / sect / questionable module. */
            AllCategories   = 0xff
        };
        Q_DECLARE_FLAGS(Categories, Category);

        /**
        * Returns the base directory for search indices
        */
        static QString getGlobalBaseIndexLocation();
        /**
        * Removes search index for this module, even if the module is not there any more
        */
        static void deleteIndexForModule( QString name );


        /**
        * Returns the config entry which is pecified by the parameter.
        */
        QString config( const CSwordModuleInfo::ConfigEntry entry ) const;

        CSwordModuleInfo( sword::SWModule* module, CSwordBackend* const = 0 );
        /** Copy constructor to copy the passed parameter.
        * @param m The module to be copied
        */
        CSwordModuleInfo( const CSwordModuleInfo& m );
        /** Reimplementation to return a valid clone.
        */
        virtual CSwordModuleInfo* clone();
        /** Destructor.
        */
        virtual ~CSwordModuleInfo();

        /**
        * Returns the module object so all objects can access the original Sword module.
        */
        sword::SWModule* module() const;
        /**
        * Sets the unlock key of the modules and writes the key into the cofig file.
        * @return True if the unlock process was succesful, if the key was wrong, or if the config file was write protected return false.
        */
        bool unlock( const QString& unlockKey );
        /**
        * Returns the display object for this module. Normally every module should have a Display object.
        * Please don't use module()->Display() because this function does return the Sword display and does
        * render the text, too.
        * This function performs some casts to return the correct display. If it returns 0 there's no valid
        * display object.
        */
        Rendering::CEntryDisplay* getDisplay() const;
        /**
        * This function does return true if the data files of the module are encrypted by the module author
        * (the on who made the module) no matter if it's locked or not.
        * @return True if this module is encryped
        */
        bool isEncrypted() const;
        /**
        * This function returns true if this module is locked (encrypted + correct cipher key),
        * otherwise return false.
        * \todo Make CSwordModuleInfo::isLocked() const.
        * @return True if this module is locked, i.e. encrypted but without a key set
        */
        bool isLocked();

        bool unlockKeyIsValid();

        /** The module version.
        * @return true if this module has a version number and false if it doesn't have one.
        */
        inline bool hasVersion() const;

        /**
        * Returns true if the module's index has been built.
        */
        virtual bool hasIndex();
        /**
        * Returns the path to this module's index base dir
        */
        virtual QString getModuleBaseIndexLocation() const;
        /**
        * Returns the path to this module's standard index
        */
        virtual QString getModuleStandardIndexLocation() const;
        /**
        * Builds a search index for this module
          */
        virtual void buildIndex();
        /**
        * Returns index size
        */
        virtual unsigned long indexSize() const;
        /**
        * Returns true if something was found, otherwise return false.
        * This function uses CLucene to perform and index based search.  It also
        * overwrites the variable containing the last search result.
        */
        virtual bool searchIndexed(const QString& searchedText, sword::ListKey& scope);
        /**
        * Returns the last search result for this module.
        * The last result is cleared by @ref search
        */
        virtual sword::ListKey& searchResult( const sword::ListKey* newResult = 0 );
        /**
        * Clears the last search result.
        * This does immediately clean the last search result,
        * no matter if search is in progress or not.
        */
        void clearSearchResult();
        /**
        * Returns the type of the module.
        */
        virtual CSwordModuleInfo::ModuleType type() const;
        /**
        * Returns the required Sword version for this module.
        * Returns -1 if no special Sword version is required.
        */
        sword::SWVersion minimumSwordVersion();
        /**
        * Returns the name of the module.
        * @return The name of this module.
        */
        QString name() const;
        /**
        * Snaps to the closest entry in the module if the current key is
        * not present in the data files.
        */
        virtual bool snap() {
            return false;
        }

        bool has( const CSwordModuleInfo::Feature ) const;
        bool has( const CSwordModuleInfo::FilterTypes  ) const;
        /**
        * Returns the text direction of the module's text.,
        */
        virtual CSwordModuleInfo::TextDirection textDirection();
        /**
        * Writes the new text at the given position into the module. This does only work for writabe modules.
        */
        virtual void write( CSwordKey* key, const QString& newText );
        /**
        * Deletes the current entry and removes it from the module.
        */
        bool deleteEntry( CSwordKey* const key );
        /**
        * Returns the language of the module.
        */
        const CLanguageMgr::Language* language() const;
        /**
        * Returns true if this module may be written by the write display windows.
        */
        inline virtual bool isWritable() const;
        /**
        * Returns true if this module is hidden (not to be shown with other modules in certain views).
        */
        inline bool isHidden() const { return m_hidden; }

        /**
          Shows or hides the module.
          \param hide Whether the module should be hidden.
          \returns whether the hidden state was changed.
        */
        bool setHidden(bool hide);

        /**
        * Returns the category of this module. See CSwordModuleInfo::Category for possible values.
        */
        CSwordModuleInfo::Category category() const;
        /**
        * The about text which belongs to this module.
        */
        QString aboutText() const;
        /**
        * Returns true if this module is Unicode encoded. False if the charset is iso8859-1.
        * Protected because it should not be used outside of the CSword*ModuleInfo classes.
        */
        inline bool isUnicode() const {
            return m_dataCache.isUnicode;
        }

    public slots:
        inline void cancelIndexing() {
            m_cancelIndexing = true;
        }

    protected:
        friend class CSwordBackend;

        inline CSwordBackend* backend() const {
            return m_backend;
        }

        inline void backend( CSwordBackend* newBackend ) {
            if (newBackend) {
                m_backend = newBackend;
            }
        }

        QString getSimpleConfigEntry(const QString& name) const;
        QString getFormattedConfigEntry(const QString& name) const;

    signals:
        void hiddenChanged(bool);
        void indexingFinished();
        void indexingProgress(int);

    private:
        sword::SWModule* m_module;
        sword::ListKey m_searchResult;

        mutable struct DataCache {
            DataCache() {
                language = 0;
            }

            QString name;
            bool isUnicode;
            CSwordModuleInfo::Category category;
            const CLanguageMgr::Language* language;
            bool hasVersion;
        }

        m_dataCache;

        CSwordBackend* m_backend;

        bool m_hidden;

        bool m_cancelIndexing;
};

Q_DECLARE_METATYPE(CSwordModuleInfo::Category);
Q_DECLARE_OPERATORS_FOR_FLAGS(CSwordModuleInfo::Categories)

inline CSwordModuleInfo::ModuleType CSwordModuleInfo::type() const {
    return CSwordModuleInfo::Unknown;
}

inline sword::SWModule* CSwordModuleInfo::module() const {
    return m_module;
}

inline bool CSwordModuleInfo::hasVersion() const {
    return m_dataCache.hasVersion;
}


/**
* Returns the name of the module.
* The Sword library takes care of the duplicate names: _n is added after each duplicate.
*/
inline QString CSwordModuleInfo::name() const {
    return m_dataCache.name;
}

/** Returns true if this module may be written by the write display windows. */
inline bool CSwordModuleInfo::isWritable() const {
    return false;
}

//#include "util/cpointers.h"

#endif