Grantlee  0.5.1
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 "template.h"
00025 #include "grantlee_core_export.h"
00026 
00027 #include <QtCore/QSharedPointer>
00028 
00029 namespace Grantlee
00030 {
00031 
00032 class AbstractLocalizer;
00033 
00035 
00046 class GRANTLEE_CORE_EXPORT AbstractTemplateLoader
00047 {
00048 public:
00052   typedef QSharedPointer<AbstractTemplateLoader> Ptr;
00053 
00057   virtual ~AbstractTemplateLoader();
00058 
00062   virtual Template loadByName( const QString &name, Engine const *engine ) const = 0;
00063 
00067   virtual QPair<QString, QString> getMediaUri( const QString &fileName ) const = 0;
00068 
00072   virtual bool canLoadTemplate( const QString &name ) const = 0;
00073 
00074 };
00075 
00077 
00123 class GRANTLEE_CORE_EXPORT FileSystemTemplateLoader : public AbstractTemplateLoader
00124 {
00125 public:
00126 #ifndef Q_QDOC
00127   typedef QSharedPointer<FileSystemTemplateLoader> Ptr;
00128 #endif
00129 
00133   FileSystemTemplateLoader();
00134 
00138   virtual ~FileSystemTemplateLoader();
00139 
00140   /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
00141 
00142   /* reimp */ bool canLoadTemplate( const QString &name ) const;
00143 
00144   /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
00145 
00149   void setTheme( const QString &themeName );
00150 
00154   QString themeName() const;
00155 
00159   void setTemplateDirs( const QStringList &dirs );
00160 
00164   QStringList templateDirs() const;
00165 
00166 private:
00167   QString m_themeName;
00168   QStringList m_templateDirs;
00169 };
00170 
00171 class LocalizedFileSystemTemplateLoaderPrivate;
00172 
00173 // ### BIC: Make l10n part of the AbstractTemplateLoader, making this class unneeded.
00180 class GRANTLEE_CORE_EXPORT LocalizedFileSystemTemplateLoader : public FileSystemTemplateLoader
00181 {
00182 public:
00183 #ifndef Q_QDOC
00184   typedef QSharedPointer<LocalizedFileSystemTemplateLoader> Ptr;
00185 #endif
00186 
00190   LocalizedFileSystemTemplateLoader( const AbstractLocalizer::Ptr localizer );
00191 
00195   virtual ~LocalizedFileSystemTemplateLoader();
00196 
00200   void setTheme( const QString &themeName );
00201 
00205   void setTemplateDirs( const QStringList &dirs );
00206 
00207 private:
00208   Q_DECLARE_PRIVATE( LocalizedFileSystemTemplateLoader )
00209   LocalizedFileSystemTemplateLoaderPrivate * const d_ptr;
00210 };
00211 
00213 
00221 class GRANTLEE_CORE_EXPORT InMemoryTemplateLoader : public AbstractTemplateLoader
00222 {
00223 public:
00224 #ifndef Q_QDOC
00225   typedef QSharedPointer<InMemoryTemplateLoader> Ptr;
00226 #endif
00227 
00228   InMemoryTemplateLoader();
00229   virtual ~InMemoryTemplateLoader();
00230 
00231   /* reimp */ Template loadByName( const QString &name, Engine const *engine ) const;
00232 
00233   /* reimp */ bool canLoadTemplate( const QString &name ) const;
00234 
00235   /* reimp */ QPair<QString, QString> getMediaUri( const QString& fileName ) const;
00236 
00251   void setTemplate( const QString &name, const QString &content );
00252 
00253 private:
00254   QHash<QString, QString> m_namedTemplates;
00255 };
00256 
00257 }
00258 
00259 #endif