Public Member Functions | Protected Member Functions | Protected Attributes

TemplateLoader Class Reference

Loads localized versions of template files. More...

#include <templateloader.h>

Inheritance diagram for TemplateLoader:
TemplateCache

List of all members.

Public Member Functions

 TemplateLoader (QSettings *settings, QObject *parent=0)
 Constructor.
virtual ~TemplateLoader ()
 Destructor.
Template getTemplate (QString templateName, QString locales=QString())
 Get a template for a given locale.

Protected Member Functions

virtual QString tryFile (QString localizedName)
 Try to get a file from cache or filesystem.

Protected Attributes

QString templatePath
 Directory where the templates are searched.
QString fileNameSuffix
 Suffix to the filenames.
QTextCodec * textCodec
 Codec for decoding the files.
QMutex mutex
 Used to synchronize threads.

Detailed Description

Loads localized versions of template files.

If the caller requests a file with the name "index" and the suffix is ".tpl" and the requested locale is "de_DE, de, en-US", then files are searched in the following order:

The following settings are required:

  path=.
  suffix=.tpl
  encoding=UTF-8
  

The path is relative to the directory of the config file. In case of windows, if the settings are in the registry, the path is relative to the current working directory.

See also:
TemplateCache

Definition at line 37 of file templateloader.h.


Constructor & Destructor Documentation

TemplateLoader::TemplateLoader ( QSettings *  settings,
QObject *  parent = 0 
)

Constructor.

Parameters:
settings configurations settings
parent parent object

Definition at line 13 of file templateloader.cpp.


Member Function Documentation

Template TemplateLoader::getTemplate ( QString  templateName,
QString  locales = QString() 
)

Get a template for a given locale.

This method is thread safe.

Parameters:
templateName base name of the template file, without suffix and without locale
locales Requested locale(s), e.g. "de_DE, en_EN". Strings in the format of the HTTP header Accept-Locale may be used. Badly formatted parts in the string are silently ignored.
Returns:
If the template cannot be loaded, an error message is logged and an empty template is returned.

Definition at line 59 of file templateloader.cpp.

QString TemplateLoader::tryFile ( QString  localizedName  )  [protected, virtual]

Try to get a file from cache or filesystem.

Parameters:
localizedName Name of the template with locale to find
Returns:
The template document, or empty string if not found

Reimplemented in TemplateCache.

Definition at line 40 of file templateloader.cpp.


The documentation for this class was generated from the following files: