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

KDECore

  • kdecore
  • services
kservicetypefactory.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  *
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 "kservicetypefactory.h"
20 #include "ksycoca.h"
21 #include "ksycocatype.h"
22 #include "ksycocadict_p.h"
23 #include "kservicetypeprofile.h"
24 
25 #include <kdebug.h>
26 #include <assert.h>
27 
28 K_GLOBAL_STATIC(KSycocaFactorySingleton<KServiceTypeFactory>, kServiceTypeFactoryInstance)
29 
30 KServiceTypeFactory::KServiceTypeFactory()
31  : KSycocaFactory( KST_KServiceTypeFactory )
32 {
33  kServiceTypeFactoryInstance->instanceCreated(this);
34  if (!KSycoca::self()->isBuilding()) {
35  QDataStream* str = stream();
36  Q_ASSERT(str);
37  if (str) {
38  // Read Header
39  qint32 n;
40  (*str) >> n;
41  if (n > 1024) {
42  KSycoca::flagError();
43  } else {
44  QString string;
45  qint32 i;
46  for(;n;--n) {
47  KSycocaEntry::read(*str, string);
48  (*str) >> i;
49  m_propertyTypeDict.insert(string, i);
50  }
51  }
52  }
53  }
54 }
55 
56 KServiceTypeFactory::~KServiceTypeFactory()
57 {
58  KServiceTypeProfile::clearCache();
59  if (kServiceTypeFactoryInstance.exists())
60  kServiceTypeFactoryInstance->instanceDestroyed(this);
61 }
62 
63 KServiceTypeFactory * KServiceTypeFactory::self()
64 {
65  return kServiceTypeFactoryInstance->self();
66 }
67 
68 KServiceType::Ptr KServiceTypeFactory::findServiceTypeByName(const QString &_name)
69 {
70  if (!sycocaDict()) return KServiceType::Ptr(); // Error!
71  assert (!KSycoca::self()->isBuilding());
72  int offset = sycocaDict()->find_string( _name );
73  if (!offset) return KServiceType::Ptr(); // Not found
74  KServiceType::Ptr newServiceType(createEntry(offset));
75 
76  // Check whether the dictionary was right.
77  if (newServiceType && (newServiceType->name() != _name))
78  {
79  // No it wasn't...
80  newServiceType = 0; // Not found
81  }
82  return newServiceType;
83 }
84 
85 QVariant::Type KServiceTypeFactory::findPropertyTypeByName(const QString &_name)
86 {
87  if (!sycocaDict())
88  return QVariant::Invalid; // Error!
89 
90  assert (!KSycoca::self()->isBuilding());
91 
92  return static_cast<QVariant::Type>( m_propertyTypeDict.value( _name, QVariant::Invalid ) );
93 }
94 
95 KServiceType::List KServiceTypeFactory::allServiceTypes()
96 {
97  KServiceType::List result;
98  const KSycocaEntry::List list = allEntries();
99  for( KSycocaEntry::List::ConstIterator it = list.begin();
100  it != list.end();
101  ++it)
102  {
103  if ( (*it)->isType( KST_KServiceType ) ) {
104  KServiceType::Ptr newServiceType = KServiceType::Ptr::staticCast( *it );
105  result.append( newServiceType );
106  }
107  }
108  return result;
109 }
110 
111 KServiceType * KServiceTypeFactory::createEntry(int offset) const
112 {
113  KServiceType *newEntry = 0;
114  KSycocaType type;
115  QDataStream *str = KSycoca::self()->findEntry(offset, type);
116  if (!str) return 0;
117 
118  switch(type)
119  {
120  case KST_KServiceType:
121  newEntry = new KServiceType(*str, offset);
122  break;
123  default:
124  kError(7011) << "KServiceTypeFactory: unexpected object entry in KSycoca database (type=" << int(type) << ")";
125  break;
126  }
127  if (newEntry && !newEntry->isValid())
128  {
129  kError(7011) << "KServiceTypeFactory: corrupt object in KSycoca database!";
130  delete newEntry;
131  newEntry = 0;
132  }
133  return newEntry;
134 }
135 
136 void KServiceTypeFactory::virtual_hook( int id, void* data )
137 { KSycocaFactory::virtual_hook( id, data ); }
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