1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
4 SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KSERVICEFACTORY_P_H
10#define KSERVICEFACTORY_P_H
11
12#include <QStringList>
13
14#include "kserviceoffer.h"
15#include "ksycocafactory_p.h"
16#include <assert.h>
17
18class KSycoca;
19class KSycocaDict;
20
21/**
22 * @internal
23 * A sycoca factory for services (e.g. applications)
24 * It loads the services from parsing directories (e.g. prefix/share/applications/)
25 * but can also create service from data streams or single config files
26 *
27 * Exported for unit tests
28 */
29class KSERVICE_EXPORT KServiceFactory : public KSycocaFactory
30{
31 K_SYCOCAFACTORY(KST_KServiceFactory)
32public:
33 /**
34 * Create factory
35 */
36 explicit KServiceFactory(KSycoca *sycoca);
37 ~KServiceFactory() override;
38
39 /**
40 * Construct a KService from a config file.
41 */
42 KSycocaEntry *createEntry(const QString &) const override
43 {
44 assert(0);
45 return nullptr;
46 }
47
48 /**
49 * Find a service (by translated name, e.g. "Terminal")
50 * (Not virtual because not used inside kbuildsycoca4, only an external service for some KDE apps)
51 */
52 KService::Ptr findServiceByName(const QString &_name);
53
54 /**
55 * Find a service (by desktop file name, e.g. "konsole")
56 */
57 virtual KService::Ptr findServiceByDesktopName(const QString &_name);
58
59 /**
60 * Find a service ( by desktop path, e.g. "System/konsole.desktop")
61 */
62 virtual KService::Ptr findServiceByDesktopPath(const QString &_name);
63
64 /**
65 * Find a service ( by menu id, e.g. "kde-konsole.desktop")
66 */
67 virtual KService::Ptr findServiceByMenuId(const QString &_menuId);
68
69 KService::Ptr findServiceByStorageId(const QString &_storageId);
70
71 /**
72 * @return the services supporting the given service type
73 * The @p serviceOffersOffset allows to jump to the right entries directly.
74 */
75 KServiceOfferList offers(int serviceTypeOffset, int serviceOffersOffset);
76
77 /**
78 * @return the services supporting the given service type
79 * The @p serviceOffersOffset allows to jump to the right entries directly.
80 */
81 KService::List serviceOffers(int serviceTypeOffset, int serviceOffersOffset);
82
83 /**
84 * Test if a specific service is associated with a specific servicetype
85 * @param serviceTypeOffset the offset of the service type being tested
86 * @param serviceOffersOffset allows to jump to the right entries for the service type directly.
87 * @param testedServiceOffset the offset of the service being tested
88 */
89 bool hasOffer(int serviceTypeOffset, int serviceOffersOffset, int testedServiceOffset);
90
91 /**
92 * @return all services. Very memory consuming, avoid using.
93 */
94 KService::List allServices();
95
96 /**
97 * Returns the directories to watch for this factory.
98 */
99 static QStringList resourceDirs();
100
101 /**
102 * @return the unique service factory, creating it if necessary
103 */
104 static KServiceFactory *self();
105
106protected:
107 KService *createEntry(int offset) const override;
108
109 // All those variables are used by KBuildServiceFactory too
110 int m_offerListOffset;
111 KSycocaDict *m_nameDict;
112 int m_nameDictOffset;
113 KSycocaDict *m_relNameDict;
114 int m_relNameDictOffset;
115 KSycocaDict *m_menuIdDict;
116 int m_menuIdDictOffset;
117
118protected:
119 void virtual_hook(int id, void *data) override;
120
121private:
122 class KServiceFactoryPrivate *d;
123};
124
125#endif
126

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