mirror of
https://github.com/YACReader/yacreader
synced 2025-07-17 20:44:32 -04:00
Update QtWebapp to 1.7.11
This commit is contained in:
14
third_party/QtWebApp/templateengine/template.cpp
vendored
14
third_party/QtWebApp/templateengine/template.cpp
vendored
@ -6,14 +6,16 @@
|
||||
#include "template.h"
|
||||
#include <QFileInfo>
|
||||
|
||||
Template::Template(QString source, QString sourceName)
|
||||
using namespace stefanfrings;
|
||||
|
||||
Template::Template(const QString source, const QString sourceName)
|
||||
: QString(source)
|
||||
{
|
||||
this->sourceName=sourceName;
|
||||
this->warnings=false;
|
||||
}
|
||||
|
||||
Template::Template(QFile& file, QTextCodec* textCodec)
|
||||
Template::Template(QFile& file, const QTextCodec* textCodec)
|
||||
{
|
||||
this->warnings=false;
|
||||
sourceName=QFileInfo(file.fileName()).baseName();
|
||||
@ -34,7 +36,7 @@ Template::Template(QFile& file, QTextCodec* textCodec)
|
||||
}
|
||||
|
||||
|
||||
int Template::setVariable(QString name, QString value)
|
||||
int Template::setVariable(const QString name, const QString value)
|
||||
{
|
||||
int count=0;
|
||||
QString variable="{"+name+"}";
|
||||
@ -52,7 +54,7 @@ int Template::setVariable(QString name, QString value)
|
||||
return count;
|
||||
}
|
||||
|
||||
int Template::setCondition(QString name, bool value)
|
||||
int Template::setCondition(const QString name, const bool value)
|
||||
{
|
||||
int count=0;
|
||||
QString startTag=QString("{if %1}").arg(name);
|
||||
@ -150,7 +152,7 @@ int Template::setCondition(QString name, bool value)
|
||||
return count;
|
||||
}
|
||||
|
||||
int Template::loop(QString name, int repetitions)
|
||||
int Template::loop(const QString name, const int repetitions)
|
||||
{
|
||||
Q_ASSERT(repetitions>=0);
|
||||
int count=0;
|
||||
@ -234,7 +236,7 @@ int Template::loop(QString name, int repetitions)
|
||||
return count;
|
||||
}
|
||||
|
||||
void Template::enableWarnings(bool enable)
|
||||
void Template::enableWarnings(const bool enable)
|
||||
{
|
||||
warnings=enable;
|
||||
}
|
||||
|
24
third_party/QtWebApp/templateengine/template.h
vendored
24
third_party/QtWebApp/templateengine/template.h
vendored
@ -14,6 +14,8 @@
|
||||
#include <QString>
|
||||
#include "templateglobal.h"
|
||||
|
||||
namespace stefanfrings {
|
||||
|
||||
/**
|
||||
Enhanced version of QString for template processing. Templates
|
||||
are usually loaded from files, but may also be loaded from
|
||||
@ -41,10 +43,10 @@
|
||||
t.setVariable("username", "Stefan");
|
||||
t.setCondition("locked",false);
|
||||
t.loop("user",2);
|
||||
t.setVariable("user0.name,"Markus");
|
||||
t.setVariable("user0.time,"8:30");
|
||||
t.setVariable("user1.name,"Roland");
|
||||
t.setVariable("user1.time,"8:45");
|
||||
t.setVariable("user0.name","Markus");
|
||||
t.setVariable("user0.time","8:30");
|
||||
t.setVariable("user1.name","Roland");
|
||||
t.setVariable("user1.time","8:45");
|
||||
</pre></code></p>
|
||||
<p>
|
||||
The code example above shows how variable within loops are numbered.
|
||||
@ -95,7 +97,7 @@ public:
|
||||
@param source The template source text
|
||||
@param sourceName Name of the source file, used for logging
|
||||
*/
|
||||
Template(QString source, QString sourceName);
|
||||
Template(const QString source, const QString sourceName);
|
||||
|
||||
/**
|
||||
Constructor that reads the template from a file. Note that this class does not
|
||||
@ -106,7 +108,7 @@ public:
|
||||
@see TemplateLoader
|
||||
@see TemplateCache
|
||||
*/
|
||||
Template(QFile& file, QTextCodec* textCodec);
|
||||
Template(QFile &file, const QTextCodec* textCodec);
|
||||
|
||||
/**
|
||||
Replace a variable by the given value.
|
||||
@ -121,7 +123,7 @@ public:
|
||||
@param value new value
|
||||
@return The count of variables that have been processed
|
||||
*/
|
||||
int setVariable(QString name, QString value);
|
||||
int setVariable(const QString name, const QString value);
|
||||
|
||||
/**
|
||||
Set a condition. This affects tags with the syntax
|
||||
@ -135,7 +137,7 @@ public:
|
||||
@param value Value of the condition
|
||||
@return The count of conditions that have been processed
|
||||
*/
|
||||
int setCondition(QString name, bool value);
|
||||
int setCondition(const QString name, bool value);
|
||||
|
||||
/**
|
||||
Set number of repetitions of a loop.
|
||||
@ -148,13 +150,13 @@ public:
|
||||
@param repetitions The number of repetitions
|
||||
@return The number of loops that have been processed
|
||||
*/
|
||||
int loop(QString name, int repetitions);
|
||||
int loop(QString name, const int repetitions);
|
||||
|
||||
/**
|
||||
Enable warnings for missing tags
|
||||
@param enable Warnings are enabled, if true
|
||||
*/
|
||||
void enableWarnings(bool enable=true);
|
||||
void enableWarnings(const bool enable=true);
|
||||
|
||||
private:
|
||||
|
||||
@ -165,4 +167,6 @@ private:
|
||||
bool warnings;
|
||||
};
|
||||
|
||||
} // end of namespace
|
||||
|
||||
#endif // TEMPLATE_H
|
||||
|
@ -3,7 +3,9 @@
|
||||
#include <QStringList>
|
||||
#include <QSet>
|
||||
|
||||
TemplateCache::TemplateCache(QSettings* settings, QObject* parent)
|
||||
using namespace stefanfrings;
|
||||
|
||||
TemplateCache::TemplateCache(const QSettings* settings, QObject* parent)
|
||||
:TemplateLoader(settings,parent)
|
||||
{
|
||||
cache.setMaxCost(settings->value("cacheSize","1000000").toInt());
|
||||
@ -11,14 +13,16 @@ TemplateCache::TemplateCache(QSettings* settings, QObject* parent)
|
||||
qDebug("TemplateCache: timeout=%i, size=%i",cacheTimeout,cache.maxCost());
|
||||
}
|
||||
|
||||
QString TemplateCache::tryFile(QString localizedName)
|
||||
QString TemplateCache::tryFile(const QString localizedName)
|
||||
{
|
||||
qint64 now=QDateTime::currentMSecsSinceEpoch();
|
||||
mutex.lock();
|
||||
// search in cache
|
||||
qDebug("TemplateCache: trying cached %s",qPrintable(localizedName));
|
||||
CacheEntry* entry=cache.object(localizedName);
|
||||
if (entry && (cacheTimeout==0 || entry->created>now-cacheTimeout))
|
||||
{
|
||||
mutex.unlock();
|
||||
return entry->document;
|
||||
}
|
||||
// search on filesystem
|
||||
@ -27,6 +31,7 @@ QString TemplateCache::tryFile(QString localizedName)
|
||||
entry->document=TemplateLoader::tryFile(localizedName);
|
||||
// Store in cache even when the file did not exist, to remember that there is no such file
|
||||
cache.insert(localizedName,entry,entry->document.size());
|
||||
mutex.unlock();
|
||||
return entry->document;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include "templateglobal.h"
|
||||
#include "templateloader.h"
|
||||
|
||||
namespace stefanfrings {
|
||||
|
||||
/**
|
||||
Caching template loader, reduces the amount of I/O and improves performance
|
||||
on remote file systems. The cache has a limited size, it prefers to keep
|
||||
@ -46,10 +48,15 @@ public:
|
||||
|
||||
/**
|
||||
Constructor.
|
||||
@param settings configurations settings
|
||||
@param settings Configuration settings, usually stored in an INI file. Must not be 0.
|
||||
Settings are read from the current group, so the caller must have called settings->beginGroup().
|
||||
Because the group must not change during runtime, it is recommended to provide a
|
||||
separate QSettings instance that is not used by other parts of the program.
|
||||
The TemplateCache does not take over ownership of the QSettings instance, so the caller
|
||||
should destroy it during shutdown.
|
||||
@param parent Parent object
|
||||
*/
|
||||
TemplateCache(QSettings* settings, QObject* parent=nullptr);
|
||||
TemplateCache(const QSettings* settings, QObject* parent=nullptr);
|
||||
|
||||
protected:
|
||||
|
||||
@ -58,7 +65,7 @@ protected:
|
||||
@param localizedName Name of the template with locale to find
|
||||
@return The template document, or empty string if not found
|
||||
*/
|
||||
virtual QString tryFile(QString localizedName);
|
||||
virtual QString tryFile(const QString localizedName);
|
||||
|
||||
private:
|
||||
|
||||
@ -73,6 +80,10 @@ private:
|
||||
/** Cache storage */
|
||||
QCache<QString,CacheEntry> cache;
|
||||
|
||||
/** Used to synchronize threads */
|
||||
QMutex mutex;
|
||||
};
|
||||
|
||||
} // end of namespace
|
||||
|
||||
#endif // TEMPLATECACHE_H
|
||||
|
@ -10,7 +10,9 @@
|
||||
#include <QDir>
|
||||
#include <QSet>
|
||||
|
||||
TemplateLoader::TemplateLoader(QSettings* settings, QObject* parent)
|
||||
using namespace stefanfrings;
|
||||
|
||||
TemplateLoader::TemplateLoader(const QSettings *settings, QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
templatePath=settings->value("path",".").toString();
|
||||
@ -64,7 +66,6 @@ QString TemplateLoader::tryFile(QString localizedName)
|
||||
|
||||
Template TemplateLoader::getTemplate(QString templateName, QString locales)
|
||||
{
|
||||
mutex.lock();
|
||||
QSet<QString> tried; // used to suppress duplicate attempts
|
||||
QStringList locs=locales.split(',',QString::SkipEmptyParts);
|
||||
|
||||
@ -78,7 +79,6 @@ Template TemplateLoader::getTemplate(QString templateName, QString locales)
|
||||
{
|
||||
QString document=tryFile(localizedName);
|
||||
if (!document.isEmpty()) {
|
||||
mutex.unlock();
|
||||
return Template(document,localizedName);
|
||||
}
|
||||
tried.insert(localizedName);
|
||||
@ -95,7 +95,6 @@ Template TemplateLoader::getTemplate(QString templateName, QString locales)
|
||||
QString document=tryFile(localizedName);
|
||||
if (!document.isEmpty())
|
||||
{
|
||||
mutex.unlock();
|
||||
return Template(document,localizedName);
|
||||
}
|
||||
tried.insert(localizedName);
|
||||
@ -106,11 +105,9 @@ Template TemplateLoader::getTemplate(QString templateName, QString locales)
|
||||
QString document=tryFile(templateName);
|
||||
if (!document.isEmpty())
|
||||
{
|
||||
mutex.unlock();
|
||||
return Template(document,templateName);
|
||||
}
|
||||
|
||||
qCritical("TemplateCache: cannot find template %s",qPrintable(templateName));
|
||||
mutex.unlock();
|
||||
return Template("",templateName);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
#include "templateglobal.h"
|
||||
#include "template.h"
|
||||
|
||||
namespace stefanfrings {
|
||||
|
||||
/**
|
||||
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",
|
||||
@ -20,7 +22,7 @@
|
||||
|
||||
- index-de_DE.tpl
|
||||
- index-de.tpl
|
||||
- index-en_US.tpl
|
||||
- index-en_US.tpl
|
||||
- index-en.tpl
|
||||
- index.tpl
|
||||
|
||||
@ -45,7 +47,7 @@ public:
|
||||
@param settings configurations settings
|
||||
@param parent parent object
|
||||
*/
|
||||
TemplateLoader(QSettings* settings, QObject* parent=nullptr);
|
||||
TemplateLoader(const QSettings* settings, QObject* parent=nullptr);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~TemplateLoader();
|
||||
@ -59,7 +61,7 @@ public:
|
||||
ignored.
|
||||
@return If the template cannot be loaded, an error message is logged and an empty template is returned.
|
||||
*/
|
||||
Template getTemplate(QString templateName, QString locales=QString());
|
||||
Template getTemplate(const QString templateName, const QString locales=QString());
|
||||
|
||||
protected:
|
||||
|
||||
@ -68,7 +70,7 @@ protected:
|
||||
@param localizedName Name of the template with locale to find
|
||||
@return The template document, or empty string if not found
|
||||
*/
|
||||
virtual QString tryFile(QString localizedName);
|
||||
virtual QString tryFile(const QString localizedName);
|
||||
|
||||
/** Directory where the templates are searched */
|
||||
QString templatePath;
|
||||
@ -78,9 +80,8 @@ protected:
|
||||
|
||||
/** Codec for decoding the files */
|
||||
QTextCodec* textCodec;
|
||||
|
||||
/** Used to synchronize threads */
|
||||
QMutex mutex;
|
||||
};
|
||||
|
||||
} // end of namespace
|
||||
|
||||
#endif // TEMPLATELOADER_H
|
||||
|
Reference in New Issue
Block a user