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