File indexing completed on 2024-12-01 06:46:30

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
0004     SPDX-FileCopyrightText: 2006-2007 David Faure <faure@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KMIMETYPEFACTORY_H
0010 #define KMIMETYPEFACTORY_H
0011 
0012 #include <assert.h>
0013 
0014 #include <QStringList>
0015 
0016 #include "ksycocafactory_p.h"
0017 
0018 class KSycoca;
0019 
0020 /**
0021  * @internal  - this header is not installed
0022  *
0023  * A sycoca factory for MIME type entries
0024  * This is only used to point to the "service offers" in ksycoca for each MIME type.
0025  * @see KMimeType
0026  */
0027 class KMimeTypeFactory : public KSycocaFactory
0028 {
0029     K_SYCOCAFACTORY(KST_KMimeTypeFactory)
0030 public:
0031     /**
0032      * Create factory
0033      */
0034     explicit KMimeTypeFactory(KSycoca *db);
0035 
0036     ~KMimeTypeFactory() override;
0037 
0038     /**
0039      * Not meant to be called at this level
0040      */
0041     KSycocaEntry *createEntry(const QString &) const override
0042     {
0043         assert(0);
0044         return nullptr;
0045     }
0046 
0047     /**
0048      * Returns the possible offset for a given MIME type entry.
0049      */
0050     int entryOffset(const QString &mimeTypeName);
0051 
0052     /**
0053      * Returns the offset into the service offers for a given MIME type.
0054      */
0055     int serviceOffersOffset(const QString &mimeTypeName);
0056 
0057     /**
0058      * Returns the directories to watch for this factory.
0059      */
0060     static QStringList resourceDirs();
0061 
0062 public:
0063     /**
0064      * @return all MIME types
0065      * Slow and memory consuming, avoid using
0066      */
0067     QStringList allMimeTypes();
0068 
0069     /**
0070      * @return the unique MIME type factory, creating it if necessary
0071      */
0072     static KMimeTypeFactory *self();
0073 
0074 public: // public for KBuildServiceFactory
0075     // A small entry for each MIME type with name and offset into the services-offer-list.
0076     class MimeTypeEntryPrivate;
0077     class KSERVICE_EXPORT MimeTypeEntry : public KSycocaEntry
0078     {
0079         Q_DECLARE_PRIVATE(MimeTypeEntry)
0080     public:
0081         typedef QExplicitlySharedDataPointer<MimeTypeEntry> Ptr;
0082 
0083         MimeTypeEntry(const QString &file, const QString &name);
0084         MimeTypeEntry(QDataStream &s, int offset);
0085         ~MimeTypeEntry() override;
0086 
0087         int serviceOffersOffset() const;
0088         void setServiceOffersOffset(int off);
0089     };
0090 
0091     MimeTypeEntry::Ptr findMimeTypeEntryByName(const QString &name);
0092 
0093 protected:
0094     MimeTypeEntry *createEntry(int offset) const override;
0095 
0096 private:
0097     // d pointer: useless since this header is not installed
0098     // class KMimeTypeFactoryPrivate* d;
0099 };
0100 
0101 #endif