1 /*
2     SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef KDEVPLATFORM_ARCHIVETEMPLATELOADER_H
8 #define KDEVPLATFORM_ARCHIVETEMPLATELOADER_H
9 
10 #include <grantlee/templateloader.h>
11 
12 class KArchiveDirectory;
13 namespace KDevelop {
14 class ArchiveTemplateLocation;
15 class ArchiveTemplateLoaderPrivate;
16 
17 class ArchiveTemplateLoader
18     : public Grantlee::AbstractTemplateLoader
19 {
20 public:
21     static ArchiveTemplateLoader* self();
22     ~ArchiveTemplateLoader() override;
23     bool canLoadTemplate(const QString& name) const override;
24     Grantlee::Template loadByName(const QString& name, const Grantlee::Engine* engine) const override;
25 
26     QPair<QString, QString> getMediaUri(const QString& fileName) const override;
27 
28 protected:
29     friend class ArchiveTemplateLocation;
30     void addLocation(ArchiveTemplateLocation* location);
31     void removeLocation(ArchiveTemplateLocation* location);
32 
33 private:
34     Q_DISABLE_COPY(ArchiveTemplateLoader)
35     ArchiveTemplateLoader();
36 
37     const QScopedPointer<class ArchiveTemplateLoaderPrivate> d_ptr;
38     Q_DECLARE_PRIVATE(ArchiveTemplateLoader)
39 };
40 
41 /**
42  * RAII class that should be used to add KArchiveDirectory locations to the engine.
43  *
44  * Adds the archive @p directory to the list of places searched for templates
45  * during the lifetime of the created ArchiveTemplateLocation class.
46  */
47 class ArchiveTemplateLocation
48 {
49 public:
50     explicit ArchiveTemplateLocation(const KArchiveDirectory* directory);
51     ~ArchiveTemplateLocation();
52 
53     bool hasTemplate(const QString& name) const;
54     QString templateContents(const QString& name) const;
55 
56 private:
57     Q_DISABLE_COPY(ArchiveTemplateLocation)
58 
59     const KArchiveDirectory* m_directory;
60 };
61 }
62 
63 #endif // KDEVPLATFORM_ARCHIVETEMPLATELOADER_H
64