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

KDED

  • 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
33KBuildServiceTypeFactory::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
42QStringList KBuildServiceTypeFactory::resourceTypes()
43{
44 return QStringList() << "servicetypes";
45}
46
47KBuildServiceTypeFactory::~KBuildServiceTypeFactory()
48{
49 delete m_resourceList;
50}
51
52KServiceType::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
61KSycocaEntry* 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() << "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() << "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() << "Invalid ServiceType : " << file;
100 delete e;
101 return 0;
102 }
103
104 return e;
105}
106
107void
108KBuildServiceTypeFactory::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
117void
118KBuildServiceTypeFactory::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
132void
133KBuildServiceTypeFactory::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
KBuildServiceTypeFactory::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kbuildservicetypefactory.cpp:108
KBuildServiceTypeFactory::createEntry
virtual KSycocaEntry * createEntry(const QString &file, const char *resource) const
Construct a KServiceType from a config file.
Definition: kbuildservicetypefactory.cpp:61
KBuildServiceTypeFactory::KBuildServiceTypeFactory
KBuildServiceTypeFactory()
Create factory.
Definition: kbuildservicetypefactory.cpp:33
KBuildServiceTypeFactory::resourceTypes
static QStringList resourceTypes()
Returns all resource types for this factory.
Definition: kbuildservicetypefactory.cpp:42
KBuildServiceTypeFactory::addEntry
virtual void addEntry(const KSycocaEntry::Ptr &newEntry)
Add entry.
Definition: kbuildservicetypefactory.cpp:133
KBuildServiceTypeFactory::findServiceTypeByName
virtual KServiceType::Ptr findServiceTypeByName(const QString &_name)
Find a service type in the database file.
Definition: kbuildservicetypefactory.cpp:52
KBuildServiceTypeFactory::save
virtual void save(QDataStream &str)
Write out service type specific index files.
Definition: kbuildservicetypefactory.cpp:118
KBuildServiceTypeFactory::~KBuildServiceTypeFactory
virtual ~KBuildServiceTypeFactory()
Definition: kbuildservicetypefactory.cpp:47
KConfigGroup
KConfigGroup::readEntry
QString readEntry(const char *key, const char *aDefault=0) const
KDesktopFile
KDesktopFile::fileName
QString fileName() const
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
KServiceTypeFactory
KServiceTypeFactory::m_propertyTypeDict
QMap< QString, int > m_propertyTypeDict
KServiceType
KSharedPtr< KServiceType >
KSharedPtr< KServiceType >::staticCast
static KSharedPtr< T > staticCast(const KSharedPtr< U > &o)
KSycocaEntry
KSycocaEntry::isValid
bool isValid() const
KSycocaEntry::isDeleted
bool isDeleted() const
KSycocaFactory::m_entryDict
KSycocaEntryDict * m_entryDict
KSycocaFactory::saveHeader
virtual void saveHeader(QDataStream &str)
KSycocaFactory::save
virtual void save(QDataStream &str)
KSycocaFactory::m_resourceList
KSycocaResourceList * m_resourceList
KSycocaFactory::addEntry
virtual void addEntry(const KSycocaEntry::Ptr &newEntry)
KSycocaResourceList
Definition: ksycocaresourcelist.h:33
KSycocaResourceList::add
void add(const QString &resource, const QString &filter)
Definition: ksycocaresourcelist.h:37
KSycoca::self
static KSycoca * self()
QMap
kWarning
#define kWarning
kbuildservicetypefactory.h
kconfiggroup.h
kdebug.h
kdesktopfile.h
kglobal.h
klocale.h
kstandarddirs.h
ksycoca.h
ksycocadict_p.h
ksycocaresourcelist.h
name
const char * name(StandardAction id)
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.

KDED

Skip menu "KDED"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • 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