File indexing completed on 2024-11-10 12:25:47
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 "ksycocaentry_p.h" 0017 #include "ksycocafactory_p.h" 0018 0019 class KSycoca; 0020 0021 /** 0022 * @internal - this header is not installed 0023 * 0024 * A sycoca factory for MIME type entries 0025 * This is only used to point to the "service offers" in ksycoca for each MIME type. 0026 * @see KMimeType 0027 */ 0028 class KMimeTypeFactory : public KSycocaFactory 0029 { 0030 K_SYCOCAFACTORY(KST_KMimeTypeFactory) 0031 public: 0032 /** 0033 * Create factory 0034 */ 0035 explicit KMimeTypeFactory(KSycoca *db); 0036 0037 ~KMimeTypeFactory() override; 0038 0039 /** 0040 * Not meant to be called at this level 0041 */ 0042 KSycocaEntry *createEntry(const QString &) const override 0043 { 0044 assert(0); 0045 return nullptr; 0046 } 0047 0048 /** 0049 * Returns the possible offset for a given MIME type entry. 0050 */ 0051 int entryOffset(const QString &mimeTypeName); 0052 0053 /** 0054 * Returns the offset into the service offers for a given MIME type. 0055 */ 0056 int serviceOffersOffset(const QString &mimeTypeName); 0057 0058 /** 0059 * Returns the directories to watch for this factory. 0060 */ 0061 static QStringList resourceDirs(); 0062 0063 public: 0064 /** 0065 * @return all MIME types 0066 * Slow and memory consuming, avoid using 0067 */ 0068 QStringList allMimeTypes(); 0069 0070 /** 0071 * @return the unique MIME type factory, creating it if necessary 0072 */ 0073 static KMimeTypeFactory *self(); 0074 0075 public: // public for KBuildServiceFactory 0076 // A small entry for each MIME type with name and offset into the services-offer-list. 0077 class MimeTypeEntryPrivate; 0078 class KSERVICE_EXPORT MimeTypeEntry : public KSycocaEntry 0079 { 0080 Q_DECLARE_PRIVATE(MimeTypeEntry) 0081 public: 0082 typedef QExplicitlySharedDataPointer<MimeTypeEntry> Ptr; 0083 0084 MimeTypeEntry(const QString &file, const QString &name); 0085 MimeTypeEntry(QDataStream &s, int offset); 0086 ~MimeTypeEntry() override; 0087 0088 int serviceOffersOffset() const; 0089 void setServiceOffersOffset(int off); 0090 }; 0091 0092 MimeTypeEntry::Ptr findMimeTypeEntryByName(const QString &name); 0093 0094 protected: 0095 MimeTypeEntry *createEntry(int offset) const override; 0096 0097 private: 0098 // d pointer: useless since this header is not installed 0099 // class KMimeTypeFactoryPrivate* d; 0100 }; 0101 0102 #endif