File indexing completed on 2024-05-12 04:37:46

0001 /*
0002     SPDX-FileCopyrightText: 2012 Miha Čančula <miha@noughmad.eu>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_ARCHIVETEMPLATELOADER_H
0008 #define KDEVPLATFORM_ARCHIVETEMPLATELOADER_H
0009 
0010 #include <grantlee/templateloader.h>
0011 
0012 class KArchiveDirectory;
0013 namespace KDevelop {
0014 class ArchiveTemplateLocation;
0015 class ArchiveTemplateLoaderPrivate;
0016 
0017 class ArchiveTemplateLoader
0018     : public Grantlee::AbstractTemplateLoader
0019 {
0020 public:
0021     static ArchiveTemplateLoader* self();
0022     ~ArchiveTemplateLoader() override;
0023     bool canLoadTemplate(const QString& name) const override;
0024     Grantlee::Template loadByName(const QString& name, const Grantlee::Engine* engine) const override;
0025 
0026     QPair<QString, QString> getMediaUri(const QString& fileName) const override;
0027 
0028 protected:
0029     friend class ArchiveTemplateLocation;
0030     void addLocation(ArchiveTemplateLocation* location);
0031     void removeLocation(ArchiveTemplateLocation* location);
0032 
0033 private:
0034     Q_DISABLE_COPY(ArchiveTemplateLoader)
0035     ArchiveTemplateLoader();
0036 
0037     const QScopedPointer<class ArchiveTemplateLoaderPrivate> d_ptr;
0038     Q_DECLARE_PRIVATE(ArchiveTemplateLoader)
0039 };
0040 
0041 /**
0042  * RAII class that should be used to add KArchiveDirectory locations to the engine.
0043  *
0044  * Adds the archive @p directory to the list of places searched for templates
0045  * during the lifetime of the created ArchiveTemplateLocation class.
0046  */
0047 class ArchiveTemplateLocation
0048 {
0049 public:
0050     explicit ArchiveTemplateLocation(const KArchiveDirectory* directory);
0051     ~ArchiveTemplateLocation();
0052 
0053     bool hasTemplate(const QString& name) const;
0054     QString templateContents(const QString& name) const;
0055 
0056 private:
0057     Q_DISABLE_COPY(ArchiveTemplateLocation)
0058 
0059     const KArchiveDirectory* m_directory;
0060 };
0061 }
0062 
0063 #endif // KDEVPLATFORM_ARCHIVETEMPLATELOADER_H