• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 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 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Jul 12 2013 08:50:17 by doxygen 1.8.3.1 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.10.5 API Reference

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