aboutsummaryrefslogtreecommitdiffstats
path: root/include/swmgr.h
blob: c9244941ff151deb1e3d94f359c7607e26be0b0a (plain) (blame)
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
/******************************************************************************
*  swmgr.h   - definition of class SWMgr used to interact with an install
*				base of sword modules.
*
* $Id: swmgr.h,v 1.48 2002/10/01 22:04:58 dglassey Exp $
*
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
*	CrossWire Bible Society
*	P. O. Box 2528
*	Tempe, AZ  85280-2528
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
*/

/** @mainpage The Sword Project 1.5.3 - API documentation
* This is the API documentation of the Sword project.
* it describes the structure of the Sword library and documents the functions of the classes.
* From time to time this documentation gives programming examples, too.
*
* Sword provides an interface to different modules (Bibles/Commentaries/Lexicons)
* on disk. The object to work directly with the modules is SWModule.
* Use the class SWMgr to manage the modules.
*
* If you want to write your own frontend for Sword please have a look at the already existing ones.
* Well knwon frontends are:\n
*	-BibleCS for Windows (the sourcecode is availble in the CVS of crosswire.org)\n
*	-GnomeSword (http://gnomesword.sourceforge.net/)\n
*	-BibleTime (http://www.bibletime.de/)\n
*/

#ifndef SWMGR_H
#define SWMGR_H

#include <sys/types.h>
#include <string>
#include <map>
#include <list>
#include <swmodule.h>
#include <swconfig.h>
#include <swlog.h>
#include <swfiltermgr.h>

#include <defs.h>

SWORD_NAMESPACE_START

typedef std::map < std::string, SWModule *, std::less < std::string > >ModMap;
typedef std::list < std::string > OptionsList;
typedef std::map < std::string, SWFilter * >FilterMap;

/** SWMgr is the main class of the Sword library.
*
* SWmgr manages the installed modules, the filters and global options like footnotes or strong numbers.
* The class SWMgr is the most important class of Sword. It is used to manage the installed modules.
* It also manages the filters (Render-, Strip- and Rawfilters).
*
* To get the SWModule objects of the instalelled modules use @ref Modules for this.
* @see AddRawFilters(), AddRenderFilters(), AddStripFilters()
* @version $Id: swmgr.h,v 1.48 2002/10/01 22:04:58 dglassey Exp $
*/
class SWDLLEXPORT SWMgr {

private:
	void commonInit(SWConfig * iconfig, SWConfig * isysconfig, bool autoload, SWFilterMgr *filterMgr);

protected:
	SWFilterMgr *filterMgr;		//made protected because because BibleTime needs it
	SWConfig * myconfig;		//made protected because because BibleTime needs it
	SWConfig *mysysconfig;
	SWConfig *homeConfig;
	void CreateMods();
	SWModule *CreateMod(std::string name, std::string driver, ConfigEntMap & section);
	void DeleteMods();
	char configType;		// 0 = file; 1 = directory
	FilterMap optionFilters;
	FilterMap cipherFilters;
	SWFilter *gbfplain;
	SWFilter *thmlplain;
	SWFilter *transliterator;
	FilterList cleanupFilters;
	OptionsList options;
	virtual void init(); // use to initialize before loading modules
	virtual char AddModToConfig(int conffd, const char *fname);
	virtual void loadConfigDir(const char *ipath);
	virtual void AddGlobalOptions(SWModule * module, ConfigEntMap & section,
	ConfigEntMap::iterator start,
	ConfigEntMap::iterator end);
	virtual void AddLocalOptions(SWModule * module, ConfigEntMap & section,
	ConfigEntMap::iterator start,
	ConfigEntMap::iterator end);
	std::list<std::string> augPaths;

	/**
	* Adds the encoding filters which are defined in "section" to the SWModule object "module".
	* @param module To this module the encoding filter(s) are added
	* @param section We use this section to get a list of filters we should apply to the module
	*/
	virtual void AddEncodingFilters(SWModule * module, ConfigEntMap & section);
	/**
	* Adds the render filters which are defined in "section" to the SWModule object "module".
	* @param module To this module the render filter(s) are added
	* @param section We use this section to get a list of filters we should apply to the module
	*/
	virtual void AddRenderFilters(SWModule * module, ConfigEntMap & section);
	/**
	* Adds the strip filters which are defined in "section" to the SWModule object "module".
	* @param module To this module the strip filter(s) are added
	* @param section We use this section to get a list of filters we should apply to the module
	*/
	virtual void AddStripFilters(SWModule * module, ConfigEntMap & section);
	/**
	* Adds the raw filters which are defined in "section" to the SWModule object "module".
	* @param module To this module the raw filter(s) are added
	* @param section We use this section to get a list of filters we should apply to the module
	*/
	virtual void AddRawFilters(SWModule * module, ConfigEntMap & section);

	virtual void augmentModules(const char *ipath);

public:

	/** Enable / Disable debug output on runtime
	* Set this to true to get more verbose output of SWMgr at runtime. Set it to false to get no debug output.
	* The default is "false".
	*/
	static bool debug;
	static bool isICU;
	static const char *globalConfPath;
	/**
	*
	*/
	static void findConfig(char *configType, char **prefixPath, char **configPath, std::list<std::string> *augPaths = 0);
	/** The global config object.
	* This is the global config object. It contains all items of all modules,
	* so lookups of entries should use this config object.
	* If you want to save a cipher key or other things to the module config file,
	* DO NOT USE this object, because it would corrupt your config files after config->Save().
	*
	* If you want to write to the modules config file read the informtaion of @ref setCipherKey() for an example of this.
	*/
	SWConfig *config;
	/**
	*
	*/
	SWConfig *sysconfig;
	/** The map of available modules.
	* This map contains thew list of available modules in Sword.
	* Here's an example how to got through the map and how toc ehck for the module type.
	*
	*@code
	* ModMap::iterator it;
	* SWModule*	curMod = 0;
	*
	* for (it = Modules.begin(); it != Modules.end(); it++) {
	*     curMod = (*it).second;
	*     if (!strcmp(curMod->Type(), "Biblical Texts")) {
	*       //do something with curMod
	*     }
	*     else if (!strcmp(curMod->Type(), "Commentaries")) {
	*       //do something with curMod
	*     }
	*     else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) {
	*       //do something with curMod
	*     }
	* }
	* @endcode
	*/
	ModMap Modules;
	/** The path to your Sword directory
	*
	*/
	char *prefixPath;
	/**
	*
	*/
	char *configPath;

	/** Constructor of SWMgr.
	*
	* @param iconfig
	* @param isysconfig
	* @param autoload If this bool is true the constructor starts loading the installed modules. If you reimplemented SWMgr you can set autoload=false to load the modules with your own reimplemented function.
	* @param filterMgr an SWFilterMgr subclass to use to manager filters on modules THIS WILL BE DELETED BY SWMgr
	*/
	SWMgr(SWConfig * iconfig = 0, SWConfig * isysconfig = 0, bool autoload = true, SWFilterMgr *filterMgr = 0);
	/**
	*
	* @param filterMgr an SWFilterMgr subclass to use to manager filters on modules THIS WILL BE DELETED BY SWMgr
	*/
	SWMgr(SWFilterMgr *filterMgr);
	/**
	*
	* @param autoload If this bool is true the constructor starts loading the
	* installed modules. If you reimplemented SWMgr you can set autoload=false
	* to load the modules with your own reimplemented function.
	* @param filterMgr an SWFilterMgr subclass to use to manager filters on
	* modules THIS WILL BE DELETED BY SWMgr
	*
	*/
	SWMgr(const char *iConfigPath, bool autoload = true, SWFilterMgr *filterMgr = 0);
	/** The destructor of SWMgr.
	* This function cleans up the modules and deletes the created object.
	* Destroy the SWMgr at last object in your application, because otherwise you may experience crashes
	* because the SWModule objects become invalid.
	*/
	virtual ~SWMgr();
	/**Installs a scan for modules in the directory givan as parameter.
	* @param dir The directory where new modules should be searched.
	*/
	virtual void InstallScan(const char *dir);
	/**  Load the modules.
	* Reimplement this function to use your own Load function,
	* for example to use your own filters.
	*/
	virtual signed char Load();
	/** Set a global option
	* Set a global option using the parameters. A global option could be for
	* example footnotes.
	* @param option The name of the option, for which you want to change the
	* value. Well known and often used values are "Footnotes" or "Strongs"
	* @param value The value. Common values are "On" and "Off"
	*/
	virtual void setGlobalOption(const char *option, const char *value);
	/** Gives the value of the given option
	* @param The option, which should be used to return the value of it
	* @return The value of the given option
	*/
	virtual const char *getGlobalOption(const char *option);
	/** Gives a description for the given option
	* @param option The option, which should be used
	* @return A description of the given option
	* @see setGlobalOption, getGlobalOption, getGlobalOptions
	*/
	virtual const char *getGlobalOptionTip(const char *option);
	/** A list of all availble options with the currently set  values
	* @return This function returns a list of global options.
	*/
	virtual OptionsList getGlobalOptions();
	/**
	*
	*/
	virtual OptionsList getGlobalOptionValues(const char *option);
	/**
	* Sets the cipher key for the given module. This function updates the key
	* at runtime, but it does not write to the config file.
	* To write the new unlock key to the config file use code like this:
	*
	* @code
	* SectionMap::iterator section;
	* ConfigEntMap::iterator entry;
	* DIR *dir = opendir(configPath);
	* struct dirent *ent;
	* char* modFile;
	* if (dir) {    // find and update .conf file
	*   rewinddir(dir);
	*   while ((ent = readdir(dir)))
	*   {
	*     if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, "..")))
	*     {
	*       modFile = m_backend->configPath;
	*       modFile += "/";
	*       modFile += ent->d_name;
	*       SWConfig *myConfig = new SWConfig( modFile );
	*       section = myConfig->Sections.find( m_module->Name() );
	*       if ( section != myConfig->Sections.end() )
	*       {
	*         entry = section->second.find("CipherKey");
	*         if (entry != section->second.end())
	*         {
	*           entry->second = unlockKey;//set cipher key
	*           myConfig->Save();//save config file
	*         }
	*       }
	*       delete myConfig;
	*     }
	*   }
	* }
	* closedir(dir);
	* @endcode
	*
	* @param modName For this module we change the unlockKey
	* @paran key This is the new unlck key we use for te module.
	*/
	virtual signed char setCipherKey(const char *modName, const char *key);
};

SWORD_NAMESPACE_END
#endif