9#include "kmimetypefactory_p.h"
10#include "ksycocaentry_p.h"
11#include "servicesdebug.h"
14#include <ksycocadict_p.h>
16extern int servicesDebugArea();
18KMimeTypeFactory::KMimeTypeFactory(
KSycoca *db)
19 : KSycocaFactory(KST_KMimeTypeFactory, db)
23KMimeTypeFactory::~KMimeTypeFactory()
27int KMimeTypeFactory::entryOffset(
const QString &mimeTypeName)
32 assert(!sycoca()->isBuilding());
33 const int offset = sycocaDict()->find_string(mimeTypeName.
toLower());
37int KMimeTypeFactory::serviceOffersOffset(
const QString &mimeTypeName)
39 const int offset = entryOffset(mimeTypeName.
toLower());
44 MimeTypeEntry::Ptr newMimeType(createEntry(offset));
49 if (newMimeType->name() != mimeTypeName.
toLower()) {
53 return newMimeType->serviceOffersOffset();
56KMimeTypeFactory::MimeTypeEntry *KMimeTypeFactory::createEntry(
int offset)
const
59 QDataStream *str = sycoca()->findEntry(offset, type);
64 if (type != KST_KMimeTypeEntry) {
65 qCWarning(SERVICES) <<
"KMimeTypeFactory: unexpected object entry in KSycoca database (type=" << int(type) <<
")";
68 MimeTypeEntry *newEntry =
new MimeTypeEntry(*str, offset);
69 if (newEntry && !newEntry->isValid()) {
70 qCWarning(SERVICES) <<
"KMimeTypeFactory: corrupt object in KSycoca database!\n";
86 Q_ASSERT(entry->isType(KST_KMimeTypeEntry));
88 MimeTypeEntry::Ptr mimeType(static_cast<MimeTypeEntry *>(entry.data()));
89 return mimeType->name();
95KMimeTypeFactory::MimeTypeEntry::Ptr KMimeTypeFactory::findMimeTypeEntryByName(
const QString &name)
97 Q_ASSERT(sycoca()->isBuilding());
100 return MimeTypeEntry::Ptr(
static_cast<MimeTypeEntry *
>(servType.
data()));
105 return KSycocaFactory::allDirectories(QStringLiteral(
"mime"));
110class KMimeTypeFactory::MimeTypeEntryPrivate :
public KSycocaEntryPrivate
113 K_SYCOCATYPE(KST_KMimeTypeEntry, KSycocaEntryPrivate)
115 : KSycocaEntryPrivate(file)
117 , m_serviceOffersOffset(-1)
121 : KSycocaEntryPrivate(s, offset)
122 , m_serviceOffersOffset(-1)
124 s >> m_name >> m_serviceOffersOffset;
133 int m_serviceOffersOffset;
136void KMimeTypeFactory::MimeTypeEntryPrivate::save(
QDataStream &s)
138 KSycocaEntryPrivate::save(s);
139 s << m_name << m_serviceOffersOffset;
144KMimeTypeFactory::MimeTypeEntry::MimeTypeEntry(
const QString &file,
const QString &name)
149KMimeTypeFactory::MimeTypeEntry::MimeTypeEntry(
QDataStream &s,
int offset)
154KMimeTypeFactory::MimeTypeEntry::~MimeTypeEntry()
158int KMimeTypeFactory::MimeTypeEntry::serviceOffersOffset()
const
160 Q_D(
const MimeTypeEntry);
161 return d->m_serviceOffersOffset;
164void KMimeTypeFactory::MimeTypeEntry::setServiceOffersOffset(
int off)
167 d->m_serviceOffersOffset = off;
Base class for all Sycoca entries.
QString name(GameStandardAction id)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const_iterator cbegin() const const
const_iterator cend() const const
void reserve(qsizetype size)
qsizetype size() const const
QString toLower() const const