Grantlee  0.5.1
templateloader.h
1 /*
2  This file is part of the Grantlee template system.
3 
4  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either version
9  2.1 of the Licence, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #ifndef GRANTLEE_TEMPLATELOADER_H
22 #define GRANTLEE_TEMPLATELOADER_H
23 
24 #include "template.h"
25 #include "grantlee_core_export.h"
26 
27 #include <QtCore/QSharedPointer>
28 
29 namespace Grantlee
30 {
31 
32 class AbstractLocalizer;
33 
35 
46 class GRANTLEE_CORE_EXPORT AbstractTemplateLoader
47 {
48 public:
52  typedef QSharedPointer<AbstractTemplateLoader> Ptr;
53 
57  virtual ~AbstractTemplateLoader();
58 
62  virtual Template loadByName( const QString &name, Engine const *engine ) const = 0;
63 
67  virtual QPair<QString, QString> getMediaUri( const QString &fileName ) const = 0;
68 
72  virtual bool canLoadTemplate( const QString &name ) const = 0;
73 
74 };
75 
77 
123 class GRANTLEE_CORE_EXPORT FileSystemTemplateLoader : public AbstractTemplateLoader
124 {
125 public:
126 #ifndef Q_QDOC
127  typedef QSharedPointer<FileSystemTemplateLoader> Ptr;
128 #endif
129 
134 
138  virtual ~FileSystemTemplateLoader();
139 
140  /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
141 
142  /* reimp */ bool canLoadTemplate( const QString &name ) const;
143 
144  /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
145 
149  void setTheme( const QString &themeName );
150 
154  QString themeName() const;
155 
159  void setTemplateDirs( const QStringList &dirs );
160 
164  QStringList templateDirs() const;
165 
166 private:
167  QString m_themeName;
168  QStringList m_templateDirs;
169 };
170 
171 class LocalizedFileSystemTemplateLoaderPrivate;
172 
173 // ### BIC: Make l10n part of the AbstractTemplateLoader, making this class unneeded.
181 {
182 public:
183 #ifndef Q_QDOC
184  typedef QSharedPointer<LocalizedFileSystemTemplateLoader> Ptr;
185 #endif
186 
191 
196 
200  void setTheme( const QString &themeName );
201 
205  void setTemplateDirs( const QStringList &dirs );
206 
207 private:
208  Q_DECLARE_PRIVATE( LocalizedFileSystemTemplateLoader )
209  LocalizedFileSystemTemplateLoaderPrivate * const d_ptr;
210 };
211 
213 
221 class GRANTLEE_CORE_EXPORT InMemoryTemplateLoader : public AbstractTemplateLoader
222 {
223 public:
224 #ifndef Q_QDOC
225  typedef QSharedPointer<InMemoryTemplateLoader> Ptr;
226 #endif
227 
229  virtual ~InMemoryTemplateLoader();
230 
231  /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
232 
233  /* reimp */ bool canLoadTemplate( const QString &name ) const;
234 
235  /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
236 
251  void setTemplate( const QString &name, const QString &content );
252 
253 private:
254  QHash<QString, QString> m_namedTemplates;
255 };
256 
257 }
258 
259 #endif
The LocalizedFileSystemTemplateLoader loads templates and l10n catalogs from the filesystem.
The Template class is a tree of nodes which may be rendered.
Definition: template.h:89
QSharedPointer< AbstractTemplateLoader > Ptr
QSharedPointer< AbstractLocalizer > Ptr
The InMemoryTemplateLoader loads Templates set dynamically in memory.
An retrieval interface to a storage location for Template objects.
The FileSystemTemplateLoader loads Templates from the file system.
Grantlee::Engine is the main entry point for creating Grantlee Templates.
Definition: engine.h:110