KCalUtils

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"
9
10#include <KTextTemplate/Engine>
11#include <QFile>
12#include <QTextStream>
13// TODO: remove this class when Grantlee support it
14using namespace KCalUtils;
15QtResourceTemplateLoader::QtResourceTemplateLoader(const QSharedPointer<KTextTemplate::AbstractLocalizer> &localizer)
16 : KTextTemplate::FileSystemTemplateLoader(localizer)
17{
18}
19
20KTextTemplate::Template QtResourceTemplateLoader::loadByName(const QString &fileName, const KTextTemplate::Engine *engine) const
21{
22 // Qt resource file
23 if (fileName.startsWith(QLatin1StringView(":/"))) {
24 QFile file;
25 file.setFileName(fileName);
26 if (!file.exists() || !file.open(QIODevice::ReadOnly | QIODevice::Text)) {
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
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
QString name(GameStandardAction id)
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 Fri Nov 29 2024 11:55:49 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.