File indexing completed on 2024-04-28 15:29:52

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KSERVICETYPEFACTORY_P_H
0009 #define KSERVICETYPEFACTORY_P_H
0010 
0011 #include <assert.h>
0012 
0013 #include <QStringList>
0014 
0015 #include "kservicetype.h"
0016 #include "ksycocafactory_p.h"
0017 
0018 class KSycoca;
0019 
0020 class KServiceType;
0021 
0022 /**
0023  * @internal
0024  * A sycoca factory for service types
0025  * It loads the service types from parsing directories (e.g. servicetypes/)
0026  * but can also create service types from data streams or single config files
0027  * @see KServiceType
0028  */
0029 class KServiceTypeFactory : public KSycocaFactory
0030 {
0031     K_SYCOCAFACTORY(KST_KServiceTypeFactory)
0032 public:
0033     /**
0034      * Create factory
0035      */
0036     explicit KServiceTypeFactory(KSycoca *db);
0037 
0038     ~KServiceTypeFactory() override;
0039 
0040     /**
0041      * Not meant to be called at this level
0042      */
0043     KSycocaEntry *createEntry(const QString &) const override
0044     {
0045         assert(0);
0046         return nullptr;
0047     }
0048 
0049     /**
0050      * Find a service type in the database file (allocates it)
0051      * Overloaded by KBuildServiceTypeFactory to return a memory one.
0052      */
0053     virtual KServiceType::Ptr findServiceTypeByName(const QString &_name);
0054 
0055     /**
0056      * Find a the property type of a named property.
0057      */
0058     QMetaType::Type findPropertyTypeByName(const QString &_name);
0059 
0060     /**
0061      * @return all servicetypes
0062      * Slow and memory consuming, avoid using
0063      */
0064     KServiceType::List allServiceTypes();
0065 
0066     /**
0067      * Returns the directories to watch for this factory.
0068      */
0069     static QStringList resourceDirs();
0070 
0071     /**
0072      * @return the unique servicetype factory, creating it if necessary
0073      */
0074     static KServiceTypeFactory *self();
0075 
0076 protected:
0077     KServiceType *createEntry(int offset) const override;
0078 
0079     // protected for KBuildServiceTypeFactory
0080     QMap<QString, int> m_propertyTypeDict;
0081 
0082 protected:
0083     void virtual_hook(int id, void *data) override;
0084 
0085 private:
0086     class KServiceTypeFactoryPrivate *d = nullptr;
0087 };
0088 
0089 #endif