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

KDECore

  • kdecore
  • services
kservicetype.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 * David Faure <faure@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation;
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "kservicetype.h"
21#include "kservicetype_p.h"
22#include "ksycoca.h"
23#include "kservice.h"
24#include "kservicetypefactory.h"
25#include "kservicefactory.h"
26#include "kservicetypeprofile.h"
27#include <assert.h>
28#include <kdebug.h>
29#include <kdesktopfile.h>
30#include <kconfiggroup.h>
31
32extern int servicesDebugArea();
33
34template QDataStream& operator>> <QString, QVariant>(QDataStream&, QMap<QString, QVariant>&);
35template QDataStream& operator<< <QString, QVariant>(QDataStream&, const QMap<QString, QVariant>&);
36
37KServiceType::KServiceType( KServiceTypePrivate &dd, const QString& _name,
38 const QString& _comment )
39 : KSycocaEntry(dd)
40{
41 Q_D(KServiceType);
42 d->m_strName = _name;
43 d->m_strComment = _comment;
44}
45
46KServiceType::KServiceType( KDesktopFile *config )
47 : KSycocaEntry(*new KServiceTypePrivate(config->fileName()))
48{
49 Q_D(KServiceType);
50 d->init(config);
51}
52
53void
54KServiceTypePrivate::init( KDesktopFile *config )
55{
56// Q_Q(KServiceType);
57
58 KConfigGroup desktopGroup = config->desktopGroup();
59 m_strName = desktopGroup.readEntry( "X-KDE-ServiceType" );
60 m_strComment = desktopGroup.readEntry("Comment");
61 deleted = desktopGroup.readEntry("Hidden", false);
62
63 // We store this as property to preserve BC, we can't change that
64 // because KSycoca needs to remain BC between KDE 2.x and KDE 3.x
65 QString sDerived = desktopGroup.readEntry( "X-KDE-Derived" );
66 m_bDerived = !sDerived.isEmpty();
67 if ( m_bDerived )
68 m_mapProps.insert( QString::fromLatin1("X-KDE-Derived"), sDerived );
69
70 const QStringList tmpList = config->groupList();
71 QStringList::const_iterator gIt = tmpList.begin();
72
73 for( ; gIt != tmpList.end(); ++gIt ) {
74 if ( (*gIt).startsWith( QLatin1String("Property::") ) ) {
75 KConfigGroup cg(config, *gIt );
76 QVariant v = QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() );
77 v = cg.readEntry( "Value", v );
78
79 if ( v.isValid() )
80 m_mapProps.insert( (*gIt).mid( 10 ), v );
81 }
82 }
83
84 gIt = tmpList.begin();
85 for( ; gIt != tmpList.end(); ++gIt ) {
86 if( (*gIt).startsWith( QLatin1String("PropertyDef::") ) ) {
87 KConfigGroup cg(config, *gIt);
88 m_mapPropDefs.insert( (*gIt).mid( 13 ),
89 QVariant::nameToType( cg.readEntry( "Type" ).toLatin1().constData() ) );
90 }
91 }
92}
93
94KServiceType::KServiceType( QDataStream& _str, int offset )
95 : KSycocaEntry(*new KServiceTypePrivate(_str, offset))
96{
97 Q_D(KServiceType);
98 d->load(_str);
99}
100
101KServiceType::KServiceType( KServiceTypePrivate &dd)
102 : KSycocaEntry(dd)
103{
104}
105
106void
107KServiceTypePrivate::load( QDataStream& _str )
108{
109 qint8 b;
110 QString dummy;
111 _str >> m_strName >> dummy >> m_strComment >> m_mapProps >> m_mapPropDefs
112 >> b >> m_serviceOffersOffset;
113 m_bDerived = m_mapProps.contains(QString::fromLatin1("X-KDE-Derived"));
114}
115
116void
117KServiceTypePrivate::save( QDataStream& _str )
118{
119 KSycocaEntryPrivate::save( _str );
120 // !! This data structure should remain binary compatible at all times !!
121 // You may add new fields at the end. Make sure to update the version
122 // number in ksycoca.h
123 _str << m_strName << QString() /*was icon*/ << m_strComment << m_mapProps << m_mapPropDefs
124 << (qint8) 1 << m_serviceOffersOffset;
125}
126
127KServiceType::~KServiceType()
128{
129}
130
131QString KServiceType::parentServiceType() const
132{
133 const QVariant v = property(QString::fromLatin1("X-KDE-Derived"));
134 return v.toString();
135}
136
137bool KServiceType::inherits( const QString& servTypeName ) const
138{
139 if ( name() == servTypeName )
140 return true;
141 QString st = parentServiceType();
142 while ( !st.isEmpty() )
143 {
144 KServiceType::Ptr ptr = KServiceType::serviceType( st );
145 if (!ptr) return false; //error
146 if ( ptr->name() == servTypeName )
147 return true;
148 st = ptr->parentServiceType();
149 }
150 return false;
151}
152
153QVariant
154KServiceTypePrivate::property( const QString& _name ) const
155{
156 QVariant v;
157
158 if ( _name == QLatin1String("Name") )
159 v = QVariant( m_strName );
160 else if ( _name == QLatin1String("Comment") )
161 v = QVariant( m_strComment );
162 else
163 v = m_mapProps.value( _name );
164
165 return v;
166}
167
168QStringList
169KServiceTypePrivate::propertyNames() const
170{
171 QStringList res = m_mapProps.keys();
172 res.append( QString::fromLatin1("Name") );
173 res.append( QString::fromLatin1("Comment") );
174 return res;
175}
176
177QVariant::Type
178KServiceType::propertyDef( const QString& _name ) const
179{
180 Q_D(const KServiceType);
181 return static_cast<QVariant::Type>( d->m_mapPropDefs.value( _name, QVariant::Invalid ) );
182}
183
184QStringList
185KServiceType::propertyDefNames() const
186{
187 Q_D(const KServiceType);
188 return d->m_mapPropDefs.keys();
189}
190
191KServiceType::Ptr KServiceType::serviceType( const QString& _name )
192{
193 return KServiceTypeFactory::self()->findServiceTypeByName( _name );
194}
195
196KServiceType::List KServiceType::allServiceTypes()
197{
198 return KServiceTypeFactory::self()->allServiceTypes();
199}
200
201KServiceType::Ptr KServiceType::parentType()
202{
203 Q_D(KServiceType);
204 if (d->m_parentTypeLoaded)
205 return d->parentType;
206
207 d->m_parentTypeLoaded = true;
208
209 const QString parentSt = parentServiceType();
210 if (parentSt.isEmpty())
211 return KServiceType::Ptr();
212
213 d->parentType = KServiceTypeFactory::self()->findServiceTypeByName( parentSt );
214 if (!d->parentType)
215 kWarning(servicesDebugArea()) << entryPath() << "specifies undefined mimetype/servicetype"<< parentSt;
216 return d->parentType;
217}
218
219void KServiceType::setServiceOffersOffset( int offset )
220{
221 Q_D(KServiceType);
222 Q_ASSERT( offset != -1 );
223 d->m_serviceOffersOffset = offset;
224}
225
226int KServiceType::serviceOffersOffset() const
227{
228 Q_D(const KServiceType);
229 return d->serviceOffersOffset();
230}
231
232QString KServiceType::comment() const
233{
234 Q_D(const KServiceType);
235 return d->comment();
236}
237
238// ## KDE4: remove?
239#ifndef KDE_NO_DEPRECATED
240QString KServiceType::desktopEntryPath() const
241{
242 return entryPath();
243}
244#endif
245
246bool KServiceType::isDerived() const
247{
248 Q_D(const KServiceType);
249 return d->m_bDerived;
250}
251
252QMap<QString,QVariant::Type> KServiceType::propertyDefs() const
253{
254 Q_D(const KServiceType);
255 return d->m_mapPropDefs;
256}
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:54
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KConfig::groupList
QStringList groupList() const
Definition: kconfig.cpp:261
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:39
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
KServiceTypePrivate
Definition: kservicetype_p.h:29
KServiceTypePrivate::propertyNames
virtual QStringList propertyNames() const
Definition: kservicetype.cpp:169
KServiceTypePrivate::m_mapProps
QMap< QString, QVariant > m_mapProps
Definition: kservicetype_p.h:73
KServiceTypePrivate::save
virtual void save(QDataStream &)
Definition: kservicetype.cpp:117
KServiceTypePrivate::m_bDerived
unsigned m_bDerived
Definition: kservicetype_p.h:74
KServiceTypePrivate::m_strName
QString m_strName
Definition: kservicetype_p.h:69
KServiceTypePrivate::m_mapPropDefs
QMap< QString, QVariant::Type > m_mapPropDefs
Definition: kservicetype_p.h:72
KServiceTypePrivate::m_serviceOffersOffset
int m_serviceOffersOffset
Definition: kservicetype_p.h:71
KServiceTypePrivate::property
virtual QVariant property(const QString &name) const
Definition: kservicetype.cpp:154
KServiceTypePrivate::init
void init(KDesktopFile *config)
Definition: kservicetype.cpp:54
KServiceTypePrivate::m_strComment
QString m_strComment
Definition: kservicetype_p.h:70
KServiceTypePrivate::load
void load(QDataStream &_str)
Definition: kservicetype.cpp:107
KServiceType
A service type is, well, a type of service, where a service is an application or plugin.
Definition: kservicetype.h:44
KServiceType::allServiceTypes
static List allServiceTypes()
Returns a list of all the supported servicetypes.
Definition: kservicetype.cpp:196
KServiceType::parentServiceType
QString parentServiceType() const
If this service type inherits from another service type, return the name of the parent.
Definition: kservicetype.cpp:131
KServiceType::isDerived
bool isDerived() const
Checks whether this service type inherits another one.
Definition: kservicetype.cpp:246
KServiceType::Ptr
KSharedPtr< KServiceType > Ptr
Definition: kservicetype.h:46
KServiceType::inherits
bool inherits(const QString &servTypeName) const
Checks whether this service type is or inherits from servTypeName.
Definition: kservicetype.cpp:137
KServiceType::propertyDefNames
QStringList propertyDefNames() const
Returns the list of all property definitions for this servicetype.
Definition: kservicetype.cpp:185
KServiceType::propertyDefs
QMap< QString, QVariant::Type > propertyDefs() const
Definition: kservicetype.cpp:252
KServiceType::propertyDef
QVariant::Type propertyDef(const QString &_name) const
Returns the type of the property definition with the given _name.
Definition: kservicetype.cpp:178
KServiceType::KServiceType
KServiceType(KDesktopFile *config)
Construct a service type and take all information from a desktop file.
Definition: kservicetype.cpp:46
KServiceType::desktopEntryPath
QString desktopEntryPath() const
Returns the relative path to the desktop entry file responsible for this servicetype.
Definition: kservicetype.cpp:240
KServiceType::serviceOffersOffset
int serviceOffersOffset() const
Definition: kservicetype.cpp:226
KServiceType::parentType
Ptr parentType()
Definition: kservicetype.cpp:201
KServiceType::serviceType
static Ptr serviceType(const QString &_name)
Returns a pointer to the servicetype '_name' or 0L if the service type is unknown.
Definition: kservicetype.cpp:191
KServiceType::comment
QString comment() const
Returns the descriptive comment associated, if any.
Definition: kservicetype.cpp:232
KServiceType::~KServiceType
virtual ~KServiceType()
Definition: kservicetype.cpp:127
KServiceType::setServiceOffersOffset
void setServiceOffersOffset(int offset)
Definition: kservicetype.cpp:219
KSharedPtr< KServiceType >
KSycocaEntryPrivate::save
virtual void save(QDataStream &s)
Definition: ksycocaentry.cpp:139
KSycocaEntryPrivate::deleted
bool deleted
Definition: ksycocaentry_p.h:76
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:42
KSycocaEntry::name
QString name() const
Definition: ksycocaentry.cpp:157
KSycocaEntry::entryPath
QString entryPath() const
Definition: ksycocaentry.cpp:104
KSycocaEntry::property
QVariant property(const QString &name) const
Returns the requested property.
Definition: ksycocaentry.cpp:169
QList< Ptr >
QMap
QStringList
QString
QVariant
kWarning
#define kWarning
Definition: kdebug.h:322
kconfiggroup.h
kdebug.h
kdesktopfile.h
servicesDebugArea
int servicesDebugArea()
Definition: kservice.cpp:47
kservice.h
kservicefactory.h
servicesDebugArea
int servicesDebugArea()
Definition: kservice.cpp:47
operator<<< QString, QVariant >
template QDataStream & operator<<< QString, QVariant >(QDataStream &, const QMap< QString, QVariant > &)
kservicetype.h
kservicetype_p.h
kservicetypefactory.h
kservicetypeprofile.h
ksycoca.h
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