Grantlee  5.1.0
templates/lib/templateloader.h
00001 /*
00002   This file is part of the Grantlee template system.
00003 
00004   Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Lesser General Public
00008   License as published by the Free Software Foundation; either version
00009   2.1 of the Licence, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Lesser General Public License for more details.
00015 
00016   You should have received a copy of the GNU Lesser General Public
00017   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 #ifndef GRANTLEE_TEMPLATELOADER_H
00022 #define GRANTLEE_TEMPLATELOADER_H
00023 
00024 #include "grantlee_templates_export.h"
00025 #include "template.h"
00026 
00027 #include <QtCore/QSharedPointer>
00028 
00029 namespace Grantlee
00030 {
00031 
00032 class AbstractLocalizer;
00033 
00035 
00049 class GRANTLEE_TEMPLATES_EXPORT AbstractTemplateLoader
00050 {
00051 public:
00055   virtual ~AbstractTemplateLoader();
00056 
00062   virtual Template loadByName(const QString &name,
00063                               Engine const *engine) const = 0;
00064 
00068   virtual QPair<QString, QString>
00069   getMediaUri(const QString &fileName) const = 0;
00070 
00074   virtual bool canLoadTemplate(const QString &name) const = 0;
00075 };
00076 
00078 
00079 class FileSystemTemplateLoaderPrivate;
00080 
00133 class GRANTLEE_TEMPLATES_EXPORT FileSystemTemplateLoader
00134     : public AbstractTemplateLoader
00135 {
00136 public:
00140   FileSystemTemplateLoader(const QSharedPointer<AbstractLocalizer> localizer
00141                            = QSharedPointer<AbstractLocalizer>());
00142 
00146   ~FileSystemTemplateLoader() override;
00147 
00148   Template loadByName(const QString &name, Engine const *engine) const override;
00149 
00150   bool canLoadTemplate(const QString &name) const override;
00151 
00152   QPair<QString, QString> getMediaUri(const QString &fileName) const override;
00153 
00157   void setTheme(const QString &themeName);
00158 
00162   QString themeName() const;
00163 
00167   void setTemplateDirs(const QStringList &dirs);
00168 
00172   QStringList templateDirs() const;
00173 
00174 private:
00175   Q_DECLARE_PRIVATE(FileSystemTemplateLoader)
00176   FileSystemTemplateLoaderPrivate *const d_ptr;
00177 };
00178 
00180 
00190 class GRANTLEE_TEMPLATES_EXPORT InMemoryTemplateLoader
00191     : public AbstractTemplateLoader
00192 {
00193 public:
00194   InMemoryTemplateLoader();
00195   ~InMemoryTemplateLoader() override;
00196 
00197   Template loadByName(const QString &name, Engine const *engine) const override;
00198 
00199   bool canLoadTemplate(const QString &name) const override;
00200 
00201   QPair<QString, QString> getMediaUri(const QString &fileName) const override;
00202 
00217   void setTemplate(const QString &name, const QString &content);
00218 
00219 private:
00220   QHash<QString, QString> m_namedTemplates;
00221 };
00222 }
00223 
00224 #endif