9#include "kservicefactory_p.h"
11#include "ksycocadict_p.h"
12#include "ksycocatype.h"
13#include "servicesdebug.h"
17extern int servicesDebugArea();
19KServiceFactory::KServiceFactory(
KSycoca *db)
20 : KSycocaFactory(KST_KServiceFactory, db)
22 , m_relNameDict(nullptr)
23 , m_menuIdDict(nullptr)
25 m_offerListOffset = 0;
27 m_relNameDictOffset = 0;
28 m_menuIdDictOffset = 0;
29 if (!sycoca()->isBuilding()) {
32 qWarning() <<
"Could not open sycoca database, you must run kbuildsycoca first!";
40 m_relNameDictOffset = i;
42 m_offerListOffset = i;
44 m_menuIdDictOffset = i;
46 const qint64 saveOffset = str->
device()->
pos();
48 m_nameDict =
new KSycocaDict(str, m_nameDictOffset);
50 m_relNameDict =
new KSycocaDict(str, m_relNameDictOffset);
52 m_menuIdDict =
new KSycocaDict(str, m_menuIdDictOffset);
57KServiceFactory::~KServiceFactory()
74 int offset = sycocaDict()->find_string(_name);
82 if (newService && (newService->name() != _name)) {
98 int offset = m_nameDict->find_string(_name);
106 if (newService && (newService->desktopEntryName() != _name)) {
115 if (!m_relNameDict) {
122 int offset = m_relNameDict->find_string(_name);
130 qCDebug(SERVICES) <<
"createEntry failed!";
135 if (newService && (newService->entryPath() != _name)) {
151 int offset = m_menuIdDict->find_string(_menuId);
159 if (newService && (newService->menuId() != _menuId)) {
173 service = findServiceByDesktopPath(_storageId);
193 service = findServiceByDesktopName(tmp);
198KService *KServiceFactory::createEntry(
int offset)
const
201 QDataStream *str = sycoca()->findEntry(offset, type);
202 if (type != KST_KService) {
203 qCWarning(SERVICES) <<
"KServiceFactory: unexpected object entry in KSycoca database (type=" << int(type) <<
")";
208 qCWarning(SERVICES) <<
"KServiceFactory: corrupt object in KSycoca database!";
219 for (
const auto &entryPtr : list) {
220 if (entryPtr->isType(KST_KService)) {
229 return KSycocaFactory::allDirectories(QStringLiteral(
"applications"));
238 str->
device()->
seek(m_offerListOffset + serviceOffersOffset);
240 qint32 aServiceTypeOffset;
241 qint32 aServiceOffset;
242 qint32 offerPreference;
243 qint32 mimeTypeInheritanceLevel;
245 (*str) >> aServiceTypeOffset;
246 if (aServiceTypeOffset) {
247 (*str) >> aServiceOffset;
248 (*str) >> offerPreference;
249 (*str) >> mimeTypeInheritanceLevel;
250 if (aServiceTypeOffset == serviceTypeOffset) {
252 const qint64 savedPos = str->
device()->
pos();
254 KService *serv = createEntry(aServiceOffset);
271KService::List KServiceFactory::serviceOffers(
int serviceTypeOffset,
int serviceOffersOffset)
277 str->
device()->
seek(m_offerListOffset + serviceOffersOffset);
279 qint32 aServiceTypeOffset;
280 qint32 aServiceOffset;
281 qint32 offerPreference;
282 qint32 mimeTypeInheritanceLevel;
284 (*str) >> aServiceTypeOffset;
285 if (aServiceTypeOffset) {
286 (*str) >> aServiceOffset;
287 (*str) >> offerPreference;
288 (*str) >> mimeTypeInheritanceLevel;
289 if (aServiceTypeOffset == serviceTypeOffset) {
291 const qint64 savedPos = str->
device()->
pos();
293 KService *serv = createEntry(aServiceOffset);
309bool KServiceFactory::hasOffer(
int serviceTypeOffset,
int serviceOffersOffset,
int testedServiceOffset)
313 const qint64 savedPos = str->
device()->
pos();
316 str->
device()->
seek(m_offerListOffset + serviceOffersOffset);
318 qint32 aServiceTypeOffset;
319 qint32 aServiceOffset;
320 qint32 offerPreference;
321 qint32 mimeTypeInheritanceLevel;
323 (*str) >> aServiceTypeOffset;
324 if (aServiceTypeOffset) {
325 (*str) >> aServiceOffset;
326 (*str) >> offerPreference;
327 (*str) >> mimeTypeInheritanceLevel;
328 if (aServiceTypeOffset == serviceTypeOffset) {
329 if (aServiceOffset == testedServiceOffset) {
344void KServiceFactory::virtual_hook(
int id,
void *data)
346 KSycocaFactory::virtual_hook(
id, data);
Holds the user's preference of a service.
Represents an installed application.
QExplicitlySharedDataPointer< KService > Ptr
A shared data pointer for KService.
Type type(const QSqlDatabase &db)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QIODevice * device() const const
bool isRelativePath(const QString &path)
bool exists() const const
virtual qint64 pos() const const
virtual bool seek(qint64 pos)
void append(QList< T > &&value)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString mid(qsizetype position, qsizetype n) const const