• 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
kbuildservicegroupfactory.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 "kbuildservicegroupfactory.h"
20 #include "ksycoca.h"
21 #include "ksycocadict_p.h"
22 #include "ksycocaresourcelist.h"
23 #include <kservicegroup_p.h>
24 
25 #include <kglobal.h>
26 #include <kstandarddirs.h>
27 #include <kdebug.h>
28 #include <klocale.h>
29 #include <assert.h>
30 #include <QtCore/QHash>
31 
32 KBuildServiceGroupFactory::KBuildServiceGroupFactory() :
33  KServiceGroupFactory()
34 {
35  m_resourceList = new KSycocaResourceList;
36 // m_resourceList->add( "apps", "*.directory" );
37 
38  m_baseGroupDict = new KSycocaDict();
39 }
40 
41 // return all service types for this factory
42 // i.e. first arguments to m_resourceList->add() above
43 QStringList KBuildServiceGroupFactory::resourceTypes()
44 {
45  return QStringList(); // << "apps";
46 }
47 
48 KBuildServiceGroupFactory::~KBuildServiceGroupFactory()
49 {
50  delete m_resourceList;
51 }
52 
53 KServiceGroup *
54 KBuildServiceGroupFactory::createEntry( const QString&, const char * ) const
55 {
56  // Unused
57  kWarning(7021) << "called!";
58  return 0;
59 }
60 
61 
62 void KBuildServiceGroupFactory::addNewEntryTo( const QString &menuName, const KService::Ptr& newEntry)
63 {
64  KSycocaEntry::Ptr ptr = m_entryDict->value(menuName);
65  KServiceGroup::Ptr entry;
66  if (ptr && ptr->isType(KST_KServiceGroup))
67  entry = KServiceGroup::Ptr::staticCast( ptr );
68 
69  if (!entry)
70  {
71  kWarning(7021) << "( " << menuName << ", " << newEntry->name() << " ): menu does not exists!";
72  return;
73  }
74  entry->addEntry( KSycocaEntry::Ptr::staticCast( newEntry ) );
75 }
76 
77 KServiceGroup::Ptr
78 KBuildServiceGroupFactory::addNew( const QString &menuName, const QString& file, KServiceGroup::Ptr entry, bool isDeleted)
79 {
80  KSycocaEntry::Ptr ptr = m_entryDict->value(menuName);
81  if (ptr)
82  {
83  kWarning(7021) << "( " << menuName << ", " << file << " ): menu already exists!";
84  return KServiceGroup::Ptr::staticCast( ptr );
85  }
86 
87  // Create new group entry
88  if (!entry)
89  entry = new KServiceGroup(file, menuName);
90 
91  entry->d_func()->m_childCount = -1; // Recalculate
92 
93  addEntry( KSycocaEntry::Ptr::staticCast(entry) );
94 
95  if (menuName != "/")
96  {
97  // Make sure parent dir exists.
98  QString parent = menuName.left(menuName.length()-1);
99  int i = parent.lastIndexOf('/');
100  if (i > 0) {
101  parent = parent.left(i+1);
102  } else {
103  parent = '/';
104  }
105 
106 
107  KServiceGroup::Ptr parentEntry;
108  ptr = m_entryDict->value(parent);
109  if (ptr && ptr->isType(KST_KServiceGroup))
110  parentEntry = KServiceGroup::Ptr::staticCast( ptr );
111  if (!parentEntry)
112  {
113  kWarning(7021) << "( " << menuName << ", " << file << " ): parent menu does not exist!";
114  }
115  else
116  {
117  if (!isDeleted && !entry->isDeleted())
118  parentEntry->addEntry( KSycocaEntry::Ptr::staticCast( entry ) );
119  }
120  }
121  return entry;
122 }
123 
124 void
125 KBuildServiceGroupFactory::addNewChild( const QString &parent, const KSycocaEntry::Ptr& newEntry)
126 {
127  QString name = "#parent#"+parent;
128 
129  KServiceGroup::Ptr entry;
130  KSycocaEntry::Ptr ptr = m_entryDict->value(name);
131  if (ptr && ptr->isType(KST_KServiceGroup))
132  entry = KServiceGroup::Ptr::staticCast( ptr );
133 
134  if (!entry)
135  {
136  entry = new KServiceGroup(name);
137  addEntry( KSycocaEntry::Ptr::staticCast( entry ) );
138  }
139  if (newEntry)
140  entry->addEntry( newEntry );
141 }
142 
143 void
144 KBuildServiceGroupFactory::addEntry( const KSycocaEntry::Ptr& newEntry)
145 {
146  KSycocaFactory::addEntry(newEntry);
147 
148  KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( newEntry );
149  serviceGroup->d_func()->m_serviceList.clear();
150 
151  if ( !serviceGroup->baseGroupName().isEmpty() )
152  {
153  m_baseGroupDict->add( serviceGroup->baseGroupName(), newEntry );
154  }
155 }
156 
157 void
158 KBuildServiceGroupFactory::saveHeader(QDataStream &str)
159 {
160  KSycocaFactory::saveHeader(str);
161 
162  str << (qint32) m_baseGroupDictOffset;
163 }
164 
165 void
166 KBuildServiceGroupFactory::save(QDataStream &str)
167 {
168  KSycocaFactory::save(str);
169 
170  m_baseGroupDictOffset = str.device()->pos();
171  m_baseGroupDict->save(str);
172 
173  int endOfFactoryData = str.device()->pos();
174 
175  // Update header (pass #3)
176  saveHeader(str);
177 
178  // Seek to end.
179  str.device()->seek(endOfFactoryData);
180 }
181 
182 KServiceGroup::Ptr KBuildServiceGroupFactory::findGroupByDesktopPath( const QString &_name, bool deep )
183 {
184  assert (KSycoca::self()->isBuilding());
185  Q_UNUSED(deep); // ?
186  // We're building a database - the service type must be in memory
187  KSycocaEntry::Ptr group = m_entryDict->value( _name );
188  return KServiceGroup::Ptr::staticCast( group );
189 }
KSycocaDict
KSharedPtr< KService >
KSycocaDict::add
void add(const QString &key, const KSycocaEntry::Ptr &payload)
KServiceGroup
kbuildservicegroupfactory.h
kdebug.h
group
KSharedPtr::clear
void clear()
KBuildServiceGroupFactory::resourceTypes
static QStringList resourceTypes()
Returns all resource types for this service factory.
Definition: kbuildservicegroupfactory.cpp:43
name
const char * name(StandardAction id)
KBuildServiceGroupFactory::addNewChild
void addNewChild(const QString &parent, const KSycocaEntry::Ptr &newEntry)
Adds the entry newEntry to the "parent group" parent, creating the group if necassery.
Definition: kbuildservicegroupfactory.cpp:125
KSycocaResourceList
Definition: ksycocaresourcelist.h:32
KBuildServiceGroupFactory::KBuildServiceGroupFactory
KBuildServiceGroupFactory()
Create factory.
Definition: kbuildservicegroupfactory.cpp:32
KBuildServiceGroupFactory::saveHeader
virtual void saveHeader(QDataStream &str)
Write out header information.
Definition: kbuildservicegroupfactory.cpp:158
QString
klocale.h
KBuildServiceGroupFactory::createEntry
virtual KServiceGroup * createEntry(const QString &, const char *) const
Create new entry.
Definition: kbuildservicegroupfactory.cpp:54
KServiceGroupFactory::m_baseGroupDict
KSycocaDict * m_baseGroupDict
KSycocaDict::save
void save(QDataStream &str)
kglobal.h
ksycocadict_p.h
KBuildServiceGroupFactory::~KBuildServiceGroupFactory
virtual ~KBuildServiceGroupFactory()
Definition: kbuildservicegroupfactory.cpp:48
KServiceGroupFactory
QStringList
kservicegroup_p.h
KBuildServiceGroupFactory::save
virtual void save(QDataStream &str)
Write out servicegroup specific index files.
Definition: kbuildservicegroupfactory.cpp:166
KBuildServiceGroupFactory::addNew
KServiceGroup::Ptr addNew(const QString &menuName, const QString &file, KServiceGroup::Ptr entry, bool isDeleted)
Add new menu menuName defined by file When entry is non-null it is re-used, otherwise a new group is ...
Definition: kbuildservicegroupfactory.cpp:78
KServiceGroupFactory::m_baseGroupDictOffset
int m_baseGroupDictOffset
ksycoca.h
kstandarddirs.h
KSharedPtr::staticCast
static KSharedPtr< T > staticCast(const KSharedPtr< U > &o)
KBuildServiceGroupFactory::addEntry
virtual void addEntry(const KSycocaEntry::Ptr &newEntry)
Add a new menu entry.
Definition: kbuildservicegroupfactory.cpp:144
KBuildServiceGroupFactory::findGroupByDesktopPath
virtual KServiceGroup::Ptr findGroupByDesktopPath(const QString &_name, bool deep=true)
Find a group ( by desktop path, e.g.
Definition: kbuildservicegroupfactory.cpp:182
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
qint32
ksycocaresourcelist.h
KSycoca::self
static KSycoca * self()
KBuildServiceGroupFactory::addNewEntryTo
void addNewEntryTo(const QString &menuName, const KService::Ptr &newEntry)
Adds the entry newEntry to the menu menuName.
Definition: kbuildservicegroupfactory.cpp:62
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