BibleTime
cdisplaytemplatemgr.h
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #pragma once
14 
15 #include <QHash>
16 #include <QString>
17 #include <QStringList>
18 #include "../../util/btassert.h"
19 #include "../drivers/btmodulelist.h"
20 #include "../drivers/cswordmoduleinfo.h"
21 
22 
23 /**
24  Manages the display templates used in the filters and display classes.
25  \note This is a singleton.
26 */
28 
29  public: // types:
30 
31  /**
32  Settings which are used to fill the content into the template.
33  */
34  struct Settings {
35 
36  char const * textDirectionAsHtmlDirAttr() const noexcept {
37  return textDirection == CSwordModuleInfo::LeftToRight ? "ltr" : "rtl";
38  }
39 
40  /** The list of modules */
42 
43  /** The title which is used for the new processed HTML page */
44  QString title;
45 
46  /** The language for the HTML page. */
47  QString langAbbrev{"en"};
48 
49  /** The CSS ID which is used in the content part of the page */
50  QString pageCSS_ID;
51 
52  /** The language direction for the HTML page. */
55 
56  };
57 
58  public: // methods:
59 
60  /**
61  \param[out] errorMessage Set to error string on error, otherwise set
62  to QString().
63  */
64  explicit CDisplayTemplateMgr(QString & errorMessage);
65 
66  /**
67  \returns the list of available templates.
68  */
69  QStringList const & availableTemplates() const
71 
72  /**
73  \brief Fills the template.
74 
75  Fills rendered content into the template given by the name.
76 
77  \param name The name of the template to fill.
78  \param content The content which should be filled into the template.
79  \param settings The settings which are used to process the templating
80  process.
81 
82  \returns The full HTML template HTML code including the CSS data.
83  */
84  QString fillTemplate(const QString & name,
85  const QString & content,
86  const Settings & settings) const;
87 
88  /**
89  \returns the name of the active template.
90  */
91  static QString activeTemplateName();
92 
93  /**
94  \returns The singleton instance of the instance of this class.
95  */
98  return m_instance;
99  }
100  /**
101  \brief Turn on or off displaying module names during parallel text rendering
102 
103  \param visible display module names
104  */
105  void setMultiModuleHeadersVisible(bool visible);
106 
107  private: // methods:
108 
109  /** Preloads a single template from disk: */
110  void loadTemplate(const QString & filename);
111  void loadCSSTemplate(const QString & filename);
112 
113  private: // fields:
114 
120 
121 };
#define BT_ASSERT(...)
Definition: btassert.h:17
QList< CSwordModuleInfo const * > BtConstModuleList
Definition: btmodulelist.h:21
CDisplayTemplateMgr(QString &errorMessage)
void setMultiModuleHeadersVisible(bool visible)
Turn on or off displaying module names during parallel text rendering.
QString fillTemplate(const QString &name, const QString &content, const Settings &settings) const
Fills the template.
static QString activeTemplateName()
QStringList const & availableTemplates() const
QHash< QString, QString > m_templateMap
void loadCSSTemplate(const QString &filename)
QHash< QString, QString > m_cssMap
static CDisplayTemplateMgr * m_instance
static CDisplayTemplateMgr * instance()
void loadTemplate(const QString &filename)
QStringList m_availableTemplateNamesCache
CSwordModuleInfo::TextDirection textDirection
char const * textDirectionAsHtmlDirAttr() const noexcept