~vcs-imports/bibletime/trunk

« back to all changes in this revision

Viewing changes to bibletime/backend/cswordbackend.h

  • Committer: mgruner
  • Date: 2007-05-08 15:51:07 UTC
  • Revision ID: vcs-imports@canonical.com-20070508155107-0rj7jdmm5ivf8685
-imported source and data files to new svn module
-this is where KDE4-based development will take place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********
 
2
*
 
3
* This file is part of BibleTime's source code, http://www.bibletime.info/.
 
4
*
 
5
* Copyright 1999-2006 by the BibleTime developers.
 
6
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
 
7
*
 
8
**********/
 
9
 
 
10
 
 
11
 
 
12
#ifndef CSWORDBACKEND_H
 
13
#define CSWORDBACKEND_H
 
14
 
 
15
//BibleTime includes
 
16
#include "cswordmoduleinfo.h"
 
17
//#include "centrydisplay.h"
 
18
 
 
19
//Qt includes
 
20
#include <qptrlist.h>
 
21
#include <qmap.h>
 
22
#include <qstring.h>
 
23
#include <qstringlist.h>
 
24
 
 
25
//Sword includes
 
26
#include <swmgr.h>
 
27
#include <swbuf.h>
 
28
#include <swmodule.h>
 
29
#include <swversion.h>
 
30
#include <localemgr.h>
 
31
#include <utilstr.h>
 
32
 
 
33
using namespace sword;
 
34
 
 
35
namespace Rendering {
 
36
 
 
37
        class CEntryDisplay;
 
38
 
 
39
        class CChapterDisplay;
 
40
 
 
41
        class CBookDisplay;
 
42
}
 
43
 
 
44
/** The backend layer main class.
 
45
 * This is the implementation of CBackend for Sword. It's additionally derived from SWMgr
 
46
 * to provide functions of Sword.
 
47
  *
 
48
  * @short The backend implementation of Sword
 
49
  * @author The BibleTime team
 
50
  * @version $Id: cswordbackend.h,v 1.58 2007/03/14 21:32:47 joachim Exp $
 
51
  */
 
52
 
 
53
class CSwordBackend : public sword::SWMgr {
 
54
 
 
55
public:
 
56
        /** Filter options. Filter options to
 
57
         * control the text display of modules. Uses int and not bool because not all
 
58
         * options have just two toggle values.
 
59
         */
 
60
 
 
61
        struct FilterOptions {
 
62
                int footnotes; /**< 0 for disabled, 1 for enabled */
 
63
                int strongNumbers; /**< 0 for disabled, 1 for enabled */
 
64
                int headings; /**< 0 for disabled, 1 for enabled */
 
65
                int morphTags; /**< 0 for disabled, 1 for enabled */
 
66
                int lemmas; /**< 0 for disabled, 1 for enabled */
 
67
                int hebrewPoints; /**< 0 for disabled, 1 for enabled */
 
68
                int hebrewCantillation; /**< 0 for disabled, 1 for enabled */
 
69
                int greekAccents; /**< 0 for disabled, 1 for enabled */
 
70
                int textualVariants; /**< Number n to enabled the n-th variant */
 
71
                int redLetterWords; /**< 0 for disabled, 1 for enabled */
 
72
                int scriptureReferences; /**< 0 for disabled, 1 for enabled */
 
73
                int morphSegmentation; /**< 0 for disabled, 1 for enabled */
 
74
        };
 
75
 
 
76
        /** Control the display of a text.
 
77
        */
 
78
 
 
79
        struct DisplayOptions {
 
80
                int lineBreaks;
 
81
                int verseNumbers;
 
82
        };
 
83
 
 
84
        /** The error codes which may be returned by the @ref Load() call.
 
85
        */
 
86
        enum LoadError { // the values exist to cast from the char return of SWMgr::Load
 
87
                NoSwordConfig = -1,
 
88
                NoError = 0,
 
89
                NoModules = 1
 
90
        };
 
91
        /**
 
92
        * The constructor of the Sword backend.
 
93
        * It creates the SWModule objects using SWMgr's methods, it adds the necessary
 
94
        * filters for the module format.
 
95
        */
 
96
        CSwordBackend();
 
97
        /**
 
98
        * The constructor of the Sword backend.
 
99
        * @param path The path which is used to load modules
 
100
        * @param augmentHome True if the $HOME/.sword/ modules should be augmented with the other modules
 
101
        */
 
102
        CSwordBackend( const QString& path, const bool augmentHome = true );
 
103
 
 
104
        /**
 
105
        * The destrctor of this backend. This function shuts the modules down using @ref shutdownModules.
 
106
        */
 
107
        virtual ~CSwordBackend();
 
108
 
 
109
        /**
 
110
        * This function returns the list of available modules managed by this backend.
 
111
        * You have to call initModules() first;
 
112
        * 
 
113
        * @return The list of modules managed by this backend
 
114
        */
 
115
        inline virtual ListCSwordModuleInfo& moduleList();
 
116
        /**
 
117
        * Initializes the Sword modules.
 
118
        *
 
119
        * @return True if the initializiation was succesful, otherwise return false.
 
120
        */
 
121
        virtual const CSwordBackend::LoadError initModules();
 
122
        /**
 
123
        * This function deinitializes the modules and deletes them.
 
124
        *
 
125
        * @return True if it was succesful, otherwise return false
 
126
        */
 
127
        virtual const bool shutdownModules();
 
128
        /**
 
129
        * Sets the given options enabled or disabled depending on the second parameter.
 
130
        *
 
131
        * @param type This is the type this function should set enabled or disabled
 
132
        * @param enable If this is true the option will be enabled, otherwise it will be disabled.
 
133
        */
 
134
        void setOption( const CSwordModuleInfo::FilterTypes type, const int state );
 
135
        void setFilterOptions( const CSwordBackend::FilterOptions options );
 
136
        void setDisplayOptions( const CSwordBackend::DisplayOptions options );
 
137
        /**
 
138
        * Returns true if the given option is enabled.
 
139
        *
 
140
        * @return Returns true if the options given as aparameter is switched on at this time, otherwise return false.
 
141
        */
 
142
        virtual const bool isOptionEnabled( const CSwordModuleInfo::FilterTypes type);
 
143
        /**
 
144
        * Sets the language for the international booknames of Sword.
 
145
        * @param langName The abbreviation string which should be used for the Sword backend
 
146
        */
 
147
        const QString booknameLanguage( const QString& langName = QString::null );
 
148
        /**
 
149
        * This function searches for a module with the specified description
 
150
        * @param description The description of the desired module
 
151
        * @return pointer to the desired module; null if no module has the specified description
 
152
        */
 
153
        virtual CSwordModuleInfo* const findModuleByDescription(const QString& description);
 
154
        /**
 
155
        * This function searches for a module with the specified description
 
156
        * @param description The description of the desired module
 
157
        * @return pointer to the desired module; null if no module has the specified description
 
158
        */
 
159
        const QString findModuleNameByDescription(const QString& description);
 
160
        /**
 
161
        * This function searches for a module with the specified name
 
162
        * @param name The name of the desired module
 
163
        * @return Pointer to the desired module; null if no module has the specified name
 
164
        */
 
165
        CSwordModuleInfo* const findModuleByName(const QString& name);
 
166
        /**
 
167
        * This function searches for a module with the specified sword module as module() object!
 
168
        * @param swmodule to a Sword module
 
169
        * @return pointer to the desired module; null if no module has the specified name
 
170
        */
 
171
        CSwordModuleInfo* const findSwordModuleByPointer(const sword::SWModule* const swmodule);
 
172
        /**
 
173
        * This function searches for a module which is the same as the passed module.
 
174
        * @param module The module which should be used for searching the new one. May be child of a different backend.
 
175
        * @return Pointer to the desired module; null if no module has the specified name
 
176
        */
 
177
        CSwordModuleInfo* const findModuleByPointer(const CSwordModuleInfo* const module);
 
178
        /**
 
179
        * @return Our global config object which contains the configs of all modules merged together.
 
180
        */
 
181
        inline sword::SWConfig* const getConfig() const;
 
182
        /**
 
183
        * Tries to find the config object for the module. The second paramter will be the found config.
 
184
        * @return True if the config was found, false if not. If false is returned the moduleConfig object is in undefined/unknwon state.
 
185
        */
 
186
        const bool moduleConfig(const QString& module, sword::SWConfig& moduleConfig );
 
187
        /**
 
188
        * Returns the text used for the option given as parameter.
 
189
        * @param The paramter enum
 
190
        * @return The name of the option given by the parameter
 
191
        */
 
192
        static const QString optionName( const CSwordModuleInfo::FilterTypes option );
 
193
        /**
 
194
        * Returns the text used for the option given as parameter.
 
195
        */
 
196
        static const QString configOptionName( const CSwordModuleInfo::FilterTypes option );
 
197
        /**
 
198
        * Returns the translated name of the option given as parameter.
 
199
        * @param The translated option name
 
200
        */
 
201
        static const QString translatedOptionName(const CSwordModuleInfo::FilterTypes option );
 
202
        /**
 
203
        * Returns the version of the Sword library.
 
204
        * @return The version used by this backend
 
205
        */
 
206
        inline virtual const sword::SWVersion Version();
 
207
        /**
 
208
        * Reload all Sword modules.
 
209
        */
 
210
        void reloadModules();
 
211
        /** Sword prefix list.
 
212
        * @return A list of all known Sword prefix dirs
 
213
        */
 
214
        const QStringList swordDirList();
 
215
 
 
216
protected:
 
217
        /**
 
218
        * Adds a render filter to the module.
 
219
        * @param module Add a render filter to this module!
 
220
        */
 
221
        virtual void AddRenderFilters(sword::SWModule *module, sword::ConfigEntMap &section);
 
222
        /**
 
223
        * Initializes the filters provided by BibleTime.
 
224
        */
 
225
        virtual void filterInit();
 
226
        
 
227
private:
 
228
        // Filters
 
229
 
 
230
        struct Filters {
 
231
                sword::SWFilter *gbf;
 
232
                sword::SWFilter *plain;
 
233
                sword::SWFilter *thml;
 
234
                sword::SWFilter *osis;
 
235
        }
 
236
 
 
237
        m_filters;
 
238
 
 
239
        struct Displays {
 
240
                Rendering::CChapterDisplay* chapter;
 
241
                Rendering::CEntryDisplay* entry;
 
242
                Rendering::CBookDisplay* book;
 
243
        }
 
244
 
 
245
        m_displays;
 
246
 
 
247
        ListCSwordModuleInfo m_moduleList;
 
248
        QMap<QString, QString> m_moduleDescriptionMap;
 
249
};
 
250
 
 
251
/**Returns The list of modules managed by this backend*/
 
252
inline ListCSwordModuleInfo& CSwordBackend::moduleList() {
 
253
        return m_moduleList;
 
254
}
 
255
 
 
256
/** Returns our local config object to store the cipher keys etc. locally for each user. The values of the config are merged with the global config. */
 
257
inline sword::SWConfig* const CSwordBackend::getConfig() const {
 
258
        return config;
 
259
}
 
260
 
 
261
/** Returns the version of the Sword library. */
 
262
inline const sword::SWVersion CSwordBackend::Version() {
 
263
        return sword::SWVersion::currentVersion;
 
264
}
 
265
 
 
266
#endif