• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • services
kservicegroupfactory.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 * Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2 as published by the Free Software Foundation;
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
12 *
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
17 **/
18
19#include "kservicegroupfactory.h"
20#include "ksycoca.h"
21#include "ksycocatype.h"
22#include "ksycocadict_p.h"
23#include "kservice.h"
24
25#include <QtCore/QCharRef>
26
27#include <klocale.h>
28#include <kdebug.h>
29#include <kglobal.h>
30#include <kstandarddirs.h>
31
32K_GLOBAL_STATIC(KSycocaFactorySingleton<KServiceGroupFactory>, kServiceGroupFactoryInstance)
33
34KServiceGroupFactory::KServiceGroupFactory()
35 : KSycocaFactory( KST_KServiceGroupFactory )
36{
37 kServiceGroupFactoryInstance->instanceCreated(this);
38 m_baseGroupDictOffset = 0;
39 if (!KSycoca::self()->isBuilding()) {
40 QDataStream* str = stream();
41 // Read Header
42 qint32 i;
43 (*str) >> i;
44 m_baseGroupDictOffset = i;
45
46 const int saveOffset = str->device()->pos();
47 // Init index tables
48 m_baseGroupDict = new KSycocaDict(str, m_baseGroupDictOffset);
49 str->device()->seek(saveOffset);
50 }
51}
52
53KServiceGroupFactory::~KServiceGroupFactory()
54{
55 delete m_baseGroupDict;
56 if (kServiceGroupFactoryInstance.exists())
57 kServiceGroupFactoryInstance->instanceDestroyed(this);
58}
59
60KServiceGroupFactory * KServiceGroupFactory::self()
61{
62 return kServiceGroupFactoryInstance->self();
63}
64
65KServiceGroup::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
66{
67 if (!sycocaDict()) return KServiceGroup::Ptr(); // Error!
68 int offset = sycocaDict()->find_string( _name );
69 if (!offset) return KServiceGroup::Ptr(); // Not found
70
71 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
72
73 // Check whether the dictionary was right.
74 if (newGroup && (newGroup->relPath() != _name))
75 {
76 // No it wasn't...
77 newGroup = 0; // Not found
78 }
79 return newGroup;
80}
81
82KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
83{
84 if (!m_baseGroupDict) return KServiceGroup::Ptr(); // Error!
85
86 // Warning : this assumes we're NOT building a database
87 // But since findBaseGroup isn't called in that case...
88 // [ see KServiceTypeFactory for how to do it if needed ]
89
90 int offset = m_baseGroupDict->find_string( _baseGroupName );
91 if (!offset) return KServiceGroup::Ptr(); // Not found
92
93 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
94
95 // Check whether the dictionary was right.
96 if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
97 {
98 // No it wasn't...
99 newGroup = 0; // Not found
100 }
101 return newGroup;
102}
103
104KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep) const
105{
106 KServiceGroup * newEntry = 0L;
107 KSycocaType type;
108 QDataStream *str = KSycoca::self()->findEntry(offset, type);
109 switch(type)
110 {
111 case KST_KServiceGroup:
112 newEntry = new KServiceGroup(*str, offset, deep);
113 break;
114
115 default:
116 kError(7011) << "KServiceGroupFactory: unexpected object entry in KSycoca database (type = " << int(type) << ")";
117 return 0;
118 }
119 if (!newEntry->isValid())
120 {
121 kError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!";
122 delete newEntry;
123 newEntry = 0;
124 }
125 return newEntry;
126}
127
128KServiceGroup* KServiceGroupFactory::createEntry(int offset) const
129{
130 return createGroup(offset, true);
131}
132
133void KServiceGroupFactory::virtual_hook( int id, void* data )
134{ KSycocaFactory::virtual_hook( id, data ); }
135
KServiceGroupFactory
Definition: kservicegroupfactory.h:39
KServiceGroupFactory::findGroupByDesktopPath
virtual KServiceGroup::Ptr findGroupByDesktopPath(const QString &_name, bool deep=true)
Find a group ( by desktop path, e.g.
Definition: kservicegroupfactory.cpp:65
KServiceGroupFactory::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
Definition: kservicegroupfactory.cpp:133
KServiceGroupFactory::createGroup
KServiceGroup * createGroup(int offset, bool deep) const
Definition: kservicegroupfactory.cpp:104
KServiceGroupFactory::~KServiceGroupFactory
virtual ~KServiceGroupFactory()
Definition: kservicegroupfactory.cpp:53
KServiceGroupFactory::findBaseGroup
KServiceGroup::Ptr findBaseGroup(const QString &_baseGroupName, bool deep=true)
Find a base group by name, e.g.
Definition: kservicegroupfactory.cpp:82
KServiceGroupFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &, const char *) const
Construct a KServiceGroup from a config file.
Definition: kservicegroupfactory.h:51
KServiceGroupFactory::self
static KServiceGroupFactory * self()
Definition: kservicegroupfactory.cpp:60
KServiceGroupFactory::m_baseGroupDict
KSycocaDict * m_baseGroupDict
Definition: kservicegroupfactory.h:71
KServiceGroup
KServiceGroup represents a group of service, for example screensavers.
Definition: kservicegroup.h:63
KServiceGroup::Ptr
KSharedPtr< KServiceGroup > Ptr
Definition: kservicegroup.h:66
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: ksharedptr.h:64
KSycocaDict
Definition: ksycocadict_p.h:37
KSycocaDict::find_string
int find_string(const QString &key) const
Looks up an entry identified by 'key'.
Definition: ksycocadict.cpp:146
KSycocaEntry::isValid
bool isValid() const
Definition: ksycocaentry.cpp:151
KSycocaFactorySingleton
Template for making it easier to define a threadsafe singleton for each factory, with support for kbu...
Definition: ksycocafactory.h:177
KSycocaFactory
Definition: ksycocafactory.h:37
KSycocaFactory::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
Definition: ksycocafactory.cpp:246
KSycocaFactory::offset
int offset() const
Definition: ksycocafactory.cpp:221
KSycocaFactory::sycocaDict
const KSycocaDict * sycocaDict() const
Definition: ksycocafactory.cpp:231
KSycoca::self
static KSycoca * self()
Get or create the only instance of KSycoca (read-only)
Definition: ksycoca.cpp:293
KSycoca::findEntry
QDataStream * findEntry(int offset, KSycocaType &type)
Definition: ksycoca.cpp:370
QString
qint32
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
This macro makes it easy to use non-POD types as global statics.
Definition: kglobal.h:221
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
Definition: kdebug.h:187
kdebug.h
kglobal.h
klocale.h
kservice.h
kservicegroupfactory.h
kstandarddirs.h
ksycoca.h
ksycocadict_p.h
ksycocatype.h
KST_KServiceGroup
@ KST_KServiceGroup
Definition: ksycocatype.h:33
KST_KServiceGroupFactory
@ KST_KServiceGroupFactory
Definition: ksycocatype.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal