GrantleeTheme

qtresourcetemplateloader.cpp
1/*
2 * SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "qtresourcetemplateloader.h"
9using namespace Qt::Literals::StringLiterals;
10
11#include <KTextTemplate/Engine>
12#include <QFile>
13#include <QTextStream>
14// TODO: remove this class when Grantlee support it
15using namespace GrantleeTheme;
16QtResourceTemplateLoader::QtResourceTemplateLoader(const QSharedPointer<KTextTemplate::AbstractLocalizer> localizer)
17 : KTextTemplate::FileSystemTemplateLoader(localizer)
18{
19}
20KTextTemplate::Template QtResourceTemplateLoader::loadByName(const QString &fileName, const KTextTemplate::Engine *engine) const
21{
22 // Qt resource file
23 if (fileName.startsWith(":/"_L1)) {
24 QFile file;
25 file.setFileName(fileName);
26 if (!file.exists() || !file.open(QIODevice::ReadOnly | QIODevice::Text)) {
27 return {};
28 }
29
30 QTextStream fstream(&file);
31 const auto fileContent = fstream.readAll();
32
33 return engine->newTemplate(fileContent, fileName);
34 } else {
36 }
37}
38
39bool QtResourceTemplateLoader::canLoadTemplate(const QString &name) const
40{
41 // Qt resource file
42 if (name.startsWith(":/"_L1)) {
43 QFile file;
44 file.setFileName(name);
45
46 if (!file.exists() || !file.open(QIODevice::ReadOnly | QIODevice::Text)) {
47 return false;
48 }
49 file.close();
50 return true;
51 } else {
53 }
54}
Template newTemplate(const QString &content, const QString &name) const
Template loadByName(const QString &name, Engine const *engine) const override
bool canLoadTemplate(const QString &name) const override
bool exists(const QString &fileName)
bool open(FILE *fh, OpenMode mode, FileHandleFlags handleFlags)
void setFileName(const QString &name)
virtual void close() override
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.