1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1999, 2007 David Faure <faure@kde.org>
4 SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KBUILD_SERVICE_FACTORY_H
10#define KBUILD_SERVICE_FACTORY_H
11
12#include <QStringList>
13
14#include "kmimeassociations_p.h"
15#include <kservicefactory_p.h>
16// We export the services to the service group factory!
17class KBuildServiceGroupFactory;
18class KBuildMimeTypeFactory;
19
20/**
21 * Service factory for building ksycoca
22 * @internal
23 */
24class KBuildServiceFactory : public KServiceFactory
25{
26public:
27 /**
28 * Create factory
29 */
30 KBuildServiceFactory(KBuildMimeTypeFactory *mimeTypeFactory);
31
32 ~KBuildServiceFactory() override;
33
34 /// Reimplemented from KServiceFactory
35 KService::Ptr findServiceByDesktopName(const QString &name) override;
36 /// Reimplemented from KServiceFactory
37 KService::Ptr findServiceByDesktopPath(const QString &name) override;
38 /// Reimplemented from KServiceFactory
39 KService::Ptr findServiceByMenuId(const QString &menuId) override;
40
41 /**
42 * Construct a KService from a config file.
43 */
44 KSycocaEntry *createEntry(const QString &file) const override;
45
46 KService *createEntry(int) const override
47 {
48 assert(0);
49 return nullptr;
50 }
51
52 /**
53 * Add a new entry.
54 */
55 void addEntry(const KSycocaEntry::Ptr &newEntry) override;
56
57 /**
58 * Write out service specific index files.
59 */
60 void save(QDataStream &str) override;
61
62 /**
63 * Write out header information
64 *
65 * Don't forget to call the parent first when you override
66 * this function.
67 */
68 void saveHeader(QDataStream &str) override;
69
70 void postProcessServices();
71
72private:
73 void populateServiceTypes();
74 void saveOfferList(QDataStream &str);
75 void collectInheritedServices();
76 void collectInheritedServices(const QString &mime, QSet<QString> &visitedMimes);
77
78 QHash<QString, KService::Ptr> m_nameMemoryHash; // m_nameDict is not usable while building ksycoca
79 QHash<QString, KService::Ptr> m_relNameMemoryHash; // m_relNameDict is not usable while building ksycoca
80 QHash<QString, KService::Ptr> m_menuIdMemoryHash; // m_menuIdDict is not usable while building ksycoca
81 QSet<KSycocaEntry::Ptr> m_dupeDict;
82
83 KOfferHash m_offerHash;
84
85 KBuildMimeTypeFactory *m_mimeTypeFactory;
86};
87
88#endif
89

source code of kservice/src/sycoca/kbuildservicefactory_p.h