summaryrefslogtreecommitdiffstats
path: root/src/renderer.h
blob: 7eb9faa8131576a08bb2b9ffe569a16dc1f08fb6 (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
/***************************************************************************
    File:         renderer.h
    Project:      Kio-Sword -- An ioslave for SWORD and KDE
    Copyright:    Copyright (C) 2004-2005 Luke Plant
 ***************************************************************************/

/***************************************************************************
 *   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; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef KS_RENDERER_H
#define KS_RENDERER_H

#include "filter.h"

#include <swmgr.h>
#include <swmodule.h>
#include <versekey.h>

#include <ntqstring.h>
#include <ntqstringlist.h>

#include <functional>
#include <vector>
#include <set>


/** Handles sword backend and prints modules 
 *
 * Renderer inherits from sword::SWMgr and handles the majority of
 * the sword stuff.  It also adds functions to 'print' text from
 * a specified module and to list available modules.
 *
 * All output is in HTML, and unicode characters are not converted
 * to HTML entities (this allows the calling function to decide
 * what encoding to use in the web page e.g. utf 8 could be used
 * and no transformation would need to be done).
 *
 */

namespace KioSword {
	class SwordOptions;
	class Template;
	
	class Renderer : public sword::SWMgr {
	
	public:
		Renderer();
		virtual ~Renderer();
	
		typedef enum {  SEARCH_WORDS,
				SEARCH_PHRASE,
				SEARCH_REGEX } SearchType;
				
		/** Return an HTML snippet of specified key from module
		*
		* @param module The sword module to print from
		* @param key    The text description of the key from the users URL
		* @param options Options for rendering text
		* @param tmplt Output parameter that should be filled with title and content
		*/
		void moduleQuery(const TQString &module, const TQString &ref, const SwordOptions &options, Template* tmplt);
		
		TQString search(const TQString &module, const TQString &query, SearchType stype, const SwordOptions &options);
		
		/** Return an HTML snippet containing a hyperlinked table of modules
		*/
		TQString listModules(const SwordOptions &options);
		void setOptions(const SwordOptions &options);
		TQStringList moduleList();
		TQStringList availableLocales();
		
		
	protected:
		typedef enum { BIBLE, COMMENTARY, LEXDICT, GENERIC, NUM_MODULE_TYPES } ModuleType ;
		enum KeyType { SWKEY, VERSEKEY, TREEKEY } ;
		void setModuleFilter(sword::SWModule *module, const SwordOptions* options);
	
		ModuleType getModuleType(sword::SWModule *module);
		TQString indexBible(sword::SWModule *module, const SwordOptions& options);
		TQString indexBook(sword::SWModule *module, const SwordOptions& options);
		TQString indexTree(sword::SWModule *module, const SwordOptions& options, bool fromTop, const int depth = -1);
		
		void verseQuery(sword::SWModule *module, const TQString &query, const SwordOptions &options,
				ModuleType modtype, Template* tmplt, TQString &navlinks);
		void treeQuery(sword::SWModule *module, const TQString &query, const SwordOptions &options,
				ModuleType modtype, Template* tmplt, TQString &navlinks);
		void normalQuery(sword::SWModule *module, const TQString &query, const SwordOptions &options,
				ModuleType modtype, Template* tmplt, TQString &navlinks);
		
		static TQString renderText(sword::SWModule *module);
		static TQString chapterList(const TQString &modname, const sword::VerseKey *vk, const SwordOptions& options);
		
		static TQString chapterLink(const TQString &modname, const sword::VerseKey *vk, const SwordOptions& options);
		static TQString chapterLink(const TQString &modname, const sword::SWKey *sk, const SwordOptions& options);
		
		static TQString bookLink(const TQString &modname, const sword::VerseKey *vk, const SwordOptions& options);
		static TQString bookLink(const TQString &modname, const sword::SWKey *sk, const SwordOptions& options);
		
		static TQString bookChapter(const sword::SWKey *sk);
		static TQString bookChapter(const sword::VerseKey *vk);
		
		static TQString bookName(const sword::SWKey *sk);
		static TQString bookName(const sword::VerseKey *vk);
		
		FilterBase *m_osisfilter;
		FilterBase *m_gbffilter;
		FilterBase *m_thmlfilter;
		sword::SWFilter *m_plainfilter;
		sword::SWFilter *m_rtffilter;
		
		std::set<sword::SWModule *, std::less<sword::SWModule *> > m_modset;
		std::vector<const char *> m_moduleTypes;
		std::vector<TQString> m_moduleTypeNames;
	
	};
}
#endif // KS_RENDERER_H