1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
4 SPDX-FileCopyrightText: 2006-2007 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KMIMETYPEFACTORY_H
10#define KMIMETYPEFACTORY_H
11
12#include <assert.h>
13
14#include <QStringList>
15
16#include "ksycocafactory_p.h"
17
18class KSycoca;
19
20/**
21 * @internal - this header is not installed
22 *
23 * A sycoca factory for MIME type entries
24 * This is only used to point to the "service offers" in ksycoca for each MIME type.
25 * @see KMimeType
26 */
27class KMimeTypeFactory : public KSycocaFactory
28{
29 K_SYCOCAFACTORY(KST_KMimeTypeFactory)
30public:
31 /**
32 * Create factory
33 */
34 explicit KMimeTypeFactory(KSycoca *db);
35
36 ~KMimeTypeFactory() override;
37
38 /**
39 * Not meant to be called at this level
40 */
41 KSycocaEntry *createEntry(const QString &) const override
42 {
43 assert(0);
44 return nullptr;
45 }
46
47 /**
48 * Returns the possible offset for a given MIME type entry.
49 */
50 int entryOffset(const QString &mimeTypeName);
51
52 /**
53 * Returns the offset into the service offers for a given MIME type.
54 */
55 int serviceOffersOffset(const QString &mimeTypeName);
56
57 /**
58 * Returns the directories to watch for this factory.
59 */
60 static QStringList resourceDirs();
61
62public:
63 /**
64 * @return all MIME types
65 * Slow and memory consuming, avoid using
66 */
67 QStringList allMimeTypes();
68
69 /**
70 * @return the unique MIME type factory, creating it if necessary
71 */
72 static KMimeTypeFactory *self();
73
74public: // public for KBuildServiceFactory
75 // A small entry for each MIME type with name and offset into the services-offer-list.
76 class MimeTypeEntryPrivate;
77 class KSERVICE_EXPORT MimeTypeEntry : public KSycocaEntry
78 {
79 Q_DECLARE_PRIVATE(MimeTypeEntry)
80 public:
81 typedef QExplicitlySharedDataPointer<MimeTypeEntry> Ptr;
82
83 MimeTypeEntry(const QString &file, const QString &name);
84 MimeTypeEntry(QDataStream &s, int offset);
85 ~MimeTypeEntry() override;
86
87 int serviceOffersOffset() const;
88 void setServiceOffersOffset(int off);
89 };
90
91 MimeTypeEntry::Ptr findMimeTypeEntryByName(const QString &name);
92
93protected:
94 MimeTypeEntry *createEntry(int offset) const override;
95
96private:
97 // d pointer: useless since this header is not installed
98 // class KMimeTypeFactoryPrivate* d;
99};
100
101#endif
102

source code of kservice/src/services/kmimetypefactory_p.h