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

KDED

  • sources
  • kde-4.12
  • kdelibs
  • kded
kbuildservicetypefactory.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright (C) 1999 David Faure <faure@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 "kbuildservicetypefactory.h"
20 #include "ksycoca.h"
21 #include "ksycocadict_p.h"
22 #include "ksycocaresourcelist.h"
23 
24 #include <kglobal.h>
25 #include <kstandarddirs.h>
26 #include <kdebug.h>
27 #include <klocale.h>
28 #include <assert.h>
29 #include <kdesktopfile.h>
30 #include <kconfiggroup.h>
31 #include <QtCore/QHash>
32 
33 KBuildServiceTypeFactory::KBuildServiceTypeFactory() :
34  KServiceTypeFactory()
35 {
36  m_resourceList = new KSycocaResourceList;
37  m_resourceList->add("servicetypes", "*.desktop");
38 }
39 
40 // return all service types for this factory
41 // i.e. first arguments to m_resourceList->add() above
42 QStringList KBuildServiceTypeFactory::resourceTypes()
43 {
44  return QStringList() << "servicetypes";
45 }
46 
47 KBuildServiceTypeFactory::~KBuildServiceTypeFactory()
48 {
49  delete m_resourceList;
50 }
51 
52 KServiceType::Ptr KBuildServiceTypeFactory::findServiceTypeByName(const QString &_name)
53 {
54  assert (KSycoca::self()->isBuilding());
55  // We're building a database - the service type must be in memory
56  KSycocaEntry::Ptr servType = m_entryDict->value( _name );
57  return KServiceType::Ptr::staticCast( servType );
58 }
59 
60 
61 KSycocaEntry* KBuildServiceTypeFactory::createEntry(const QString &file, const char *resource) const
62 {
63  QString name = file;
64  int pos = name.lastIndexOf('/');
65  if (pos != -1) {
66  name = name.mid(pos+1);
67  }
68 
69  if (name.isEmpty())
70  return 0;
71 
72  KDesktopFile desktopFile(resource, file);
73  const KConfigGroup desktopGroup = desktopFile.desktopGroup();
74 
75  if ( desktopGroup.readEntry( "Hidden", false ) == true )
76  return 0;
77 
78  const QString type = desktopGroup.readEntry( "Type" );
79  if ( type != QLatin1String( "ServiceType" ) ) {
80  kWarning(7012) << "The service type config file " << desktopFile.fileName() << " has Type=" << type << " instead of Type=ServiceType";
81  return 0;
82  }
83 
84  const QString serviceType = desktopGroup.readEntry( "X-KDE-ServiceType" );
85 
86  if ( serviceType.isEmpty() ) {
87  kWarning(7012) << "The service type config file " << desktopFile.fileName() << " does not contain a ServiceType=... entry";
88  return 0;
89  }
90 
91  KServiceType* e = new KServiceType( &desktopFile );
92 
93  if (e->isDeleted()) {
94  delete e;
95  return 0;
96  }
97 
98  if ( !(e->isValid()) ) {
99  kWarning(7012) << "Invalid ServiceType : " << file;
100  delete e;
101  return 0;
102  }
103 
104  return e;
105 }
106 
107 void
108 KBuildServiceTypeFactory::saveHeader(QDataStream &str)
109 {
110  KSycocaFactory::saveHeader(str);
111  str << (qint32) m_propertyTypeDict.count();
112  for (QMap<QString, int>::ConstIterator it = m_propertyTypeDict.constBegin(); it != m_propertyTypeDict.constEnd(); ++it) {
113  str << it.key() << (qint32)it.value();
114  }
115 }
116 
117 void
118 KBuildServiceTypeFactory::save(QDataStream &str)
119 {
120  KSycocaFactory::save(str);
121 #if 0 // not needed since don't have any additional index anymore
122  int endOfFactoryData = str.device()->pos();
123 
124  // Update header (pass #3)
125  saveHeader(str);
126 
127  // Seek to end.
128  str.device()->seek(endOfFactoryData);
129 #endif
130 }
131 
132 void
133 KBuildServiceTypeFactory::addEntry(const KSycocaEntry::Ptr& newEntry)
134 {
135  KSycocaFactory::addEntry(newEntry);
136 
137  KServiceType::Ptr serviceType = KServiceType::Ptr::staticCast( newEntry );
138 
139  const QMap<QString,QVariant::Type>& pd = serviceType->propertyDefs();
140  QMap<QString,QVariant::Type>::ConstIterator pit = pd.begin();
141  for( ; pit != pd.end(); ++pit ) {
142  const QString property = pit.key();
143  QMap<QString, int>::iterator dictit = m_propertyTypeDict.find(property);
144  if (dictit == m_propertyTypeDict.end())
145  m_propertyTypeDict.insert(property, pit.value());
146  else if (*dictit != static_cast<int>(pit.value()))
147  kWarning(7021) << "Property '"<< property << "' is defined multiple times ("<< serviceType->name() <<")";
148  }
149 }
150 
kdebug.h
KServiceTypeFactory::m_propertyTypeDict
QMap< QString, int > m_propertyTypeDict
KBuildServiceTypeFactory::addEntry
virtual void addEntry(const KSycocaEntry::Ptr &newEntry)
Add entry.
Definition: kbuildservicetypefactory.cpp:133
name
const char * name(StandardAction id)
KSycocaResourceList
Definition: ksycocaresourcelist.h:32
KServiceType
QString
KServiceTypeFactory
kdesktopfile.h
KBuildServiceTypeFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &file, const char *resource) const
Construct a KServiceType from a config file.
Definition: kbuildservicetypefactory.cpp:61
klocale.h
KBuildServiceTypeFactory::KBuildServiceTypeFactory
KBuildServiceTypeFactory()
Create factory.
Definition: kbuildservicetypefactory.cpp:33
KBuildServiceTypeFactory::~KBuildServiceTypeFactory
virtual ~KBuildServiceTypeFactory()
Definition: kbuildservicetypefactory.cpp:47
KBuildServiceTypeFactory::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kbuildservicetypefactory.cpp:108
kglobal.h
kbuildservicetypefactory.h
ksycocadict_p.h
KSycocaEntry
QStringList
KSycocaResourceList::add
void add(const QString &resource, const QString &filter)
Definition: ksycocaresourcelist.h:37
KBuildServiceTypeFactory::findServiceTypeByName
virtual KServiceType::Ptr findServiceTypeByName(const QString &_name)
Find a service type in the database file.
Definition: kbuildservicetypefactory.cpp:52
KDesktopFile
ksycoca.h
KConfigGroup
KDesktopFile::fileName
QString fileName() const
kstandarddirs.h
KBuildServiceTypeFactory::resourceTypes
static QStringList resourceTypes()
Returns all resource types for this factory.
Definition: kbuildservicetypefactory.cpp:42
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
qint32
ksycocaresourcelist.h
KBuildServiceTypeFactory::save
virtual void save(QDataStream &str)
Write out service type specific index files.
Definition: kbuildservicetypefactory.cpp:118
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KSycoca::self
static KSycoca * self()
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
QMap
kconfiggroup.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:51:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDED

Skip menu "KDED"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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