• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.3 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 
32 extern int servicesDebugArea();
33 
34 template QDataStream& operator>> <QString, QVariant>(QDataStream&, QMap<QString, QVariant>&);
35 template QDataStream& operator<< <QString, QVariant>(QDataStream&, const QMap<QString, QVariant>&);
36 
37 KServiceType::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 
46 KServiceType::KServiceType( KDesktopFile *config )
47  : KSycocaEntry(*new KServiceTypePrivate(config->fileName()))
48 {
49  Q_D(KServiceType);
50  d->init(config);
51 }
52 
53 void
54 KServiceTypePrivate::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 
94 KServiceType::KServiceType( QDataStream& _str, int offset )
95  : KSycocaEntry(*new KServiceTypePrivate(_str, offset))
96 {
97  Q_D(KServiceType);
98  d->load(_str);
99 }
100 
101 KServiceType::KServiceType( KServiceTypePrivate &dd)
102  : KSycocaEntry(dd)
103 {
104 }
105 
106 void
107 KServiceTypePrivate::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 
116 void
117 KServiceTypePrivate::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 
127 KServiceType::~KServiceType()
128 {
129 }
130 
131 QString KServiceType::parentServiceType() const
132 {
133  const QVariant v = property(QString::fromLatin1("X-KDE-Derived"));
134  return v.toString();
135 }
136 
137 bool 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 
153 QVariant
154 KServiceTypePrivate::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 
168 QStringList
169 KServiceTypePrivate::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 
177 QVariant::Type
178 KServiceType::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 
184 QStringList
185 KServiceType::propertyDefNames() const
186 {
187  Q_D(const KServiceType);
188  return d->m_mapPropDefs.keys();
189 }
190 
191 KServiceType::Ptr KServiceType::serviceType( const QString& _name )
192 {
193  return KServiceTypeFactory::self()->findServiceTypeByName( _name );
194 }
195 
196 KServiceType::List KServiceType::allServiceTypes()
197 {
198  return KServiceTypeFactory::self()->allServiceTypes();
199 }
200 
201 KServiceType::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 
219 void KServiceType::setServiceOffersOffset( int offset )
220 {
221  Q_D(KServiceType);
222  Q_ASSERT( offset != -1 );
223  d->m_serviceOffersOffset = offset;
224 }
225 
226 int KServiceType::serviceOffersOffset() const
227 {
228  Q_D(const KServiceType);
229  return d->serviceOffersOffset();
230 }
231 
232 QString KServiceType::comment() const
233 {
234  Q_D(const KServiceType);
235  return d->comment();
236 }
237 
238 // ## KDE4: remove?
239 #ifndef KDE_NO_DEPRECATED
240 QString KServiceType::desktopEntryPath() const
241 {
242  return entryPath();
243 }
244 #endif
245 
246 bool KServiceType::isDerived() const
247 {
248  Q_D(const KServiceType);
249  return d->m_bDerived;
250 }
251 
252 QMap<QString,QVariant::Type> KServiceType::propertyDefs() const
253 {
254  Q_D(const KServiceType);
255  return d->m_mapPropDefs;
256 }
QVariant
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
KSharedPtr< KServiceType >
KServiceType::serviceType
static Ptr serviceType(const QString &_name)
Returns a pointer to the servicetype &#39;_name&#39; or 0L if the service type is unknown.
Definition: kservicetype.cpp:191
KServiceType::allServiceTypes
static List allServiceTypes()
Returns a list of all the supported servicetypes.
Definition: kservicetype.cpp:196
KFileSystemType::Type
Type
Definition: kfilesystemtype_p.h:28
KServiceTypePrivate::init
void init(KDesktopFile *config)
Definition: kservicetype.cpp:54
kdebug.h
KServiceTypePrivate::propertyNames
virtual QStringList propertyNames() const
Definition: kservicetype.cpp:169
KServiceType::~KServiceType
virtual ~KServiceType()
Definition: kservicetype.cpp:127
KServiceTypeFactory::self
static KServiceTypeFactory * self()
Definition: kservicetypefactory.cpp:63
KServiceTypePrivate::m_bDerived
unsigned m_bDerived
Definition: kservicetype_p.h:74
KServiceTypePrivate::property
virtual QVariant property(const QString &name) const
Definition: kservicetype.cpp:154
KServiceTypePrivate::m_strName
QString m_strName
Definition: kservicetype_p.h:69
servicesDebugArea
int servicesDebugArea()
Definition: kservice.cpp:47
KServiceType
A service type is, well, a type of service, where a service is an application or plugin.
Definition: kservicetype.h:43
QString
KServiceTypePrivate::m_strComment
QString m_strComment
Definition: kservicetype_p.h:70
kdesktopfile.h
KServiceTypePrivate::m_serviceOffersOffset
int m_serviceOffersOffset
Definition: kservicetype_p.h:71
KServiceType::KServiceType
KServiceType(KDesktopFile *config)
Construct a service type and take all information from a desktop file.
Definition: kservicetype.cpp:46
KServiceType::propertyDef
QVariant::Type propertyDef(const QString &_name) const
Returns the type of the property definition with the given _name.
Definition: kservicetype.cpp:178
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:138
kservicefactory.h
KSycocaEntryPrivate::save
virtual void save(QDataStream &s)
Definition: ksycocaentry.cpp:139
KServiceType::isDerived
bool isDerived() const
Checks whether this service type inherits another one.
Definition: kservicetype.cpp:246
KSycocaEntry::entryPath
QString entryPath() const
Definition: ksycocaentry.cpp:104
kservicetypeprofile.h
KServiceType::desktopEntryPath
QString desktopEntryPath() const
Returns the relative path to the desktop entry file responsible for this servicetype.
Definition: kservicetype.cpp:240
KServiceType::parentType
Ptr parentType()
Definition: kservicetype.cpp:201
kservicetypefactory.h
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:41
KConfig::groupList
QStringList groupList() const
Definition: kconfig.cpp:291
QStringList
KServiceTypePrivate::load
void load(QDataStream &_str)
Definition: kservicetype.cpp:107
KServiceTypePrivate::m_mapProps
QMap< QString, QVariant > m_mapProps
Definition: kservicetype_p.h:73
kservice.h
KServiceType::setServiceOffersOffset
void setServiceOffersOffset(int offset)
Definition: kservicetype.cpp:219
KSycocaEntryPrivate::deleted
bool deleted
Definition: ksycocaentry_p.h:76
KServiceType::serviceOffersOffset
int serviceOffersOffset() const
Definition: kservicetype.cpp:226
kWarning
#define kWarning
Definition: kdebug.h:322
kservicetype.h
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:38
ksycoca.h
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:53
KServiceType::propertyDefNames
QStringList propertyDefNames() const
Returns the list of all property definitions for this servicetype.
Definition: kservicetype.cpp:185
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::inherits
bool inherits(const QString &servTypeName) const
Checks whether this service type is or inherits from servTypeName.
Definition: kservicetype.cpp:137
KSycocaEntry::offset
int offset() const
Definition: ksycocaentry.cpp:133
KServiceTypePrivate::save
virtual void save(QDataStream &)
Definition: kservicetype.cpp:117
kservicetype_p.h
KServiceTypePrivate::m_mapPropDefs
QMap< QString, QVariant::Type > m_mapPropDefs
Definition: kservicetype_p.h:72
KServiceType::comment
QString comment() const
Returns the descriptive comment associated, if any.
Definition: kservicetype.cpp:232
operator<< < QString, QVariant >
template QDataStream & operator<< < QString, QVariant >(QDataStream &, const QMap< QString, QVariant > &)
KSycocaEntry::property
QVariant property(const QString &name) const
Returns the requested property.
Definition: ksycocaentry.cpp:169
KServiceTypeFactory::allServiceTypes
KServiceType::List allServiceTypes()
Definition: kservicetypefactory.cpp:95
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
KSycocaEntry::name
QString name() const
Definition: ksycocaentry.cpp:157
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
Definition: kdesktopfile.cpp:73
KServiceType::propertyDefs
QMap< QString, QVariant::Type > propertyDefs() const
Definition: kservicetype.cpp:252
KServiceTypePrivate
Definition: kservicetype_p.h:28
QMap
kconfiggroup.h
QList< Ptr >
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Thu Dec 12 2013 07:58:44 by doxygen 1.8.5 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.11.3 API Reference

Skip menu "kdelibs-4.11.3 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