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

KDECore

  • kdecore
  • services
kservicegroupfactory.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright (C) 2000 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 "kservicegroupfactory.h"
20 #include "ksycoca.h"
21 #include "ksycocatype.h"
22 #include "ksycocadict_p.h"
23 #include "kservice.h"
24 
25 #include <QtCore/QCharRef>
26 
27 #include <klocale.h>
28 #include <kdebug.h>
29 #include <kglobal.h>
30 #include <kstandarddirs.h>
31 
32 K_GLOBAL_STATIC(KSycocaFactorySingleton<KServiceGroupFactory>, kServiceGroupFactoryInstance)
33 
34 KServiceGroupFactory::KServiceGroupFactory()
35  : KSycocaFactory( KST_KServiceGroupFactory )
36 {
37  kServiceGroupFactoryInstance->instanceCreated(this);
38  m_baseGroupDictOffset = 0;
39  if (!KSycoca::self()->isBuilding()) {
40  QDataStream* str = stream();
41  // Read Header
42  qint32 i;
43  (*str) >> i;
44  m_baseGroupDictOffset = i;
45 
46  const int saveOffset = str->device()->pos();
47  // Init index tables
48  m_baseGroupDict = new KSycocaDict(str, m_baseGroupDictOffset);
49  str->device()->seek(saveOffset);
50  }
51 }
52 
53 KServiceGroupFactory::~KServiceGroupFactory()
54 {
55  delete m_baseGroupDict;
56  if (kServiceGroupFactoryInstance.exists())
57  kServiceGroupFactoryInstance->instanceDestroyed(this);
58 }
59 
60 KServiceGroupFactory * KServiceGroupFactory::self()
61 {
62  return kServiceGroupFactoryInstance->self();
63 }
64 
65 KServiceGroup::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
66 {
67  if (!sycocaDict()) return KServiceGroup::Ptr(); // Error!
68  int offset = sycocaDict()->find_string( _name );
69  if (!offset) return KServiceGroup::Ptr(); // Not found
70 
71  KServiceGroup::Ptr newGroup(createGroup(offset, deep));
72 
73  // Check whether the dictionary was right.
74  if (newGroup && (newGroup->relPath() != _name))
75  {
76  // No it wasn't...
77  newGroup = 0; // Not found
78  }
79  return newGroup;
80 }
81 
82 KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
83 {
84  if (!m_baseGroupDict) return KServiceGroup::Ptr(); // Error!
85 
86  // Warning : this assumes we're NOT building a database
87  // But since findBaseGroup isn't called in that case...
88  // [ see KServiceTypeFactory for how to do it if needed ]
89 
90  int offset = m_baseGroupDict->find_string( _baseGroupName );
91  if (!offset) return KServiceGroup::Ptr(); // Not found
92 
93  KServiceGroup::Ptr newGroup(createGroup(offset, deep));
94 
95  // Check whether the dictionary was right.
96  if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
97  {
98  // No it wasn't...
99  newGroup = 0; // Not found
100  }
101  return newGroup;
102 }
103 
104 KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep) const
105 {
106  KServiceGroup * newEntry = 0L;
107  KSycocaType type;
108  QDataStream *str = KSycoca::self()->findEntry(offset, type);
109  switch(type)
110  {
111  case KST_KServiceGroup:
112  newEntry = new KServiceGroup(*str, offset, deep);
113  break;
114 
115  default:
116  kError(7011) << "KServiceGroupFactory: unexpected object entry in KSycoca database (type = " << int(type) << ")";
117  return 0;
118  }
119  if (!newEntry->isValid())
120  {
121  kError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!";
122  delete newEntry;
123  newEntry = 0;
124  }
125  return newEntry;
126 }
127 
128 KServiceGroup* KServiceGroupFactory::createEntry(int offset) const
129 {
130  return createGroup(offset, true);
131 }
132 
133 void KServiceGroupFactory::virtual_hook( int id, void* data )
134 { KSycocaFactory::virtual_hook( id, data ); }
135 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Apr 16 2013 19:11:43 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.2 API Reference

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