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

KDECore

  • kdecore
  • services
kservicetypefactory.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 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 "kservicetypefactory.h"
20#include "ksycoca.h"
21#include "ksycocatype.h"
22#include "ksycocadict_p.h"
23#include "kservicetypeprofile.h"
24
25#include <kdebug.h>
26#include <assert.h>
27
28K_GLOBAL_STATIC(KSycocaFactorySingleton<KServiceTypeFactory>, kServiceTypeFactoryInstance)
29
30KServiceTypeFactory::KServiceTypeFactory()
31 : KSycocaFactory( KST_KServiceTypeFactory )
32{
33 kServiceTypeFactoryInstance->instanceCreated(this);
34 if (!KSycoca::self()->isBuilding()) {
35 QDataStream* str = stream();
36 Q_ASSERT(str);
37 if (str) {
38 // Read Header
39 qint32 n;
40 (*str) >> n;
41 if (n > 1024) {
42 KSycoca::flagError();
43 } else {
44 QString string;
45 qint32 i;
46 for(;n;--n) {
47 KSycocaEntry::read(*str, string);
48 (*str) >> i;
49 m_propertyTypeDict.insert(string, i);
50 }
51 }
52 }
53 }
54}
55
56KServiceTypeFactory::~KServiceTypeFactory()
57{
58 KServiceTypeProfile::clearCache();
59 if (kServiceTypeFactoryInstance.exists())
60 kServiceTypeFactoryInstance->instanceDestroyed(this);
61}
62
63KServiceTypeFactory * KServiceTypeFactory::self()
64{
65 return kServiceTypeFactoryInstance->self();
66}
67
68KServiceType::Ptr KServiceTypeFactory::findServiceTypeByName(const QString &_name)
69{
70 if (!sycocaDict()) return KServiceType::Ptr(); // Error!
71 assert (!KSycoca::self()->isBuilding());
72 int offset = sycocaDict()->find_string( _name );
73 if (!offset) return KServiceType::Ptr(); // Not found
74 KServiceType::Ptr newServiceType(createEntry(offset));
75
76 // Check whether the dictionary was right.
77 if (newServiceType && (newServiceType->name() != _name))
78 {
79 // No it wasn't...
80 newServiceType = 0; // Not found
81 }
82 return newServiceType;
83}
84
85QVariant::Type KServiceTypeFactory::findPropertyTypeByName(const QString &_name)
86{
87 if (!sycocaDict())
88 return QVariant::Invalid; // Error!
89
90 assert (!KSycoca::self()->isBuilding());
91
92 return static_cast<QVariant::Type>( m_propertyTypeDict.value( _name, QVariant::Invalid ) );
93}
94
95KServiceType::List KServiceTypeFactory::allServiceTypes()
96{
97 KServiceType::List result;
98 const KSycocaEntry::List list = allEntries();
99 for( KSycocaEntry::List::ConstIterator it = list.begin();
100 it != list.end();
101 ++it)
102 {
103 if ( (*it)->isType( KST_KServiceType ) ) {
104 KServiceType::Ptr newServiceType = KServiceType::Ptr::staticCast( *it );
105 result.append( newServiceType );
106 }
107 }
108 return result;
109}
110
111KServiceType * KServiceTypeFactory::createEntry(int offset) const
112{
113 KServiceType *newEntry = 0;
114 KSycocaType type;
115 QDataStream *str = KSycoca::self()->findEntry(offset, type);
116 if (!str) return 0;
117
118 switch(type)
119 {
120 case KST_KServiceType:
121 newEntry = new KServiceType(*str, offset);
122 break;
123 default:
124 kError(7011) << "KServiceTypeFactory: unexpected object entry in KSycoca database (type=" << int(type) << ")";
125 break;
126 }
127 if (newEntry && !newEntry->isValid())
128 {
129 kError(7011) << "KServiceTypeFactory: corrupt object in KSycoca database!";
130 delete newEntry;
131 newEntry = 0;
132 }
133 return newEntry;
134}
135
136void KServiceTypeFactory::virtual_hook( int id, void* data )
137{ KSycocaFactory::virtual_hook( id, data ); }
KServiceTypeFactory
Definition: kservicetypefactory.h:44
KServiceTypeFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &, const char *) const
Not meant to be called at this level.
Definition: kservicetypefactory.h:57
KServiceTypeFactory::findPropertyTypeByName
QVariant::Type findPropertyTypeByName(const QString &_name)
Find a the property type of a named property.
Definition: kservicetypefactory.cpp:85
KServiceTypeFactory::m_propertyTypeDict
QMap< QString, int > m_propertyTypeDict
Definition: kservicetypefactory.h:86
KServiceTypeFactory::~KServiceTypeFactory
virtual ~KServiceTypeFactory()
Definition: kservicetypefactory.cpp:56
KServiceTypeFactory::virtual_hook
virtual void virtual_hook(int id, void *data)
Virtual hook, used to add new "virtual" functions while maintaining binary compatibility.
Definition: kservicetypefactory.cpp:136
KServiceTypeFactory::allServiceTypes
KServiceType::List allServiceTypes()
Definition: kservicetypefactory.cpp:95
KServiceTypeFactory::findServiceTypeByName
virtual KServiceType::Ptr findServiceTypeByName(const QString &_name)
Find a service type in the database file (allocates it) Overloaded by KBuildServiceTypeFactory to ret...
Definition: kservicetypefactory.cpp:68
KServiceTypeFactory::self
static KServiceTypeFactory * self()
Definition: kservicetypefactory.cpp:63
KServiceType
A service type is, well, a type of service, where a service is an application or plugin.
Definition: kservicetype.h:44
KServiceType::Ptr
KSharedPtr< KServiceType > Ptr
Definition: kservicetype.h:46
KSharedPtr< KServiceType >
KSharedPtr< KServiceType >::staticCast
static KSharedPtr< KServiceType > staticCast(const KSharedPtr< U > &o)
Convert KSharedPtr to KSharedPtr<T>, using a static_cast.
Definition: ksharedptr.h:173
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
KSycocaEntry::name
QString name() const
Definition: ksycocaentry.cpp:157
KSycocaEntry::read
static void read(QDataStream &s, QString &str)
Default constructor.
Definition: ksycocaentry.cpp:46
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::allEntries
virtual KSycocaEntry::List allEntries() const
Get a list of all entries from the database.
Definition: ksycocafactory.cpp:183
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
KSycoca::flagError
static void flagError()
A read error occurs.
Definition: ksycoca.cpp:559
QList< Ptr >
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
kservicetypefactory.h
kservicetypeprofile.h
ksycoca.h
ksycocadict_p.h
ksycocatype.h
KST_KServiceTypeFactory
@ KST_KServiceTypeFactory
Definition: ksycocatype.h:45
KST_KServiceType
@ KST_KServiceType
Definition: ksycocatype.h:31
KServiceTypeProfile::clearCache
void clearCache()
Clear all cached information.
Definition: kservicetypeprofile.cpp:103
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