• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdeio
 

tdeio/tdeio

  • tdeio
  • tdeio
kservicegroupfactory.cpp
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 "tdesycoca.h"
21 #include "tdesycocatype.h"
22 #include "tdesycocadict.h"
23 #include "kservice.h"
24 
25 #include <tqstring.h>
26 
27 #include <tdelocale.h>
28 #include <kdebug.h>
29 #include <tdeglobal.h>
30 #include <kstandarddirs.h>
31 
32 KServiceGroupFactory::KServiceGroupFactory()
33  : KSycocaFactory( KST_KServiceGroupFactory )
34 {
35  m_baseGroupDictOffset = 0;
36  if (m_str)
37  {
38  // Read Header
39  TQ_INT32 i;
40  (*m_str) >> i;
41  m_baseGroupDictOffset = i;
42 
43  int saveOffset = m_str->device()->at();
44  // Init index tables
45  m_baseGroupDict = new KSycocaDict(m_str, m_baseGroupDictOffset);
46  m_str->device()->at(saveOffset);
47  }
48  else
49  {
50  // Build new database
51  m_baseGroupDict = new KSycocaDict();
52  }
53  _self = this;
54 }
55 
56 KServiceGroupFactory::~KServiceGroupFactory()
57 {
58  _self = 0L;
59  delete m_baseGroupDict;
60 }
61 
62 KServiceGroupFactory * KServiceGroupFactory::self()
63 {
64  if (!_self)
65  _self = new KServiceGroupFactory();
66  return _self;
67 }
68 
69 KServiceGroup * KServiceGroupFactory::findGroupByDesktopPath(const TQString &_name, bool deep)
70 {
71  if (!m_sycocaDict) return 0; // Error!
72 
73  // Warning : this assumes we're NOT building a database
74  // But since findServiceByName isn't called in that case...
75  // [ see KServiceTypeFactory for how to do it if needed ]
76 
77  int offset = m_sycocaDict->find_string( _name );
78  if (!offset) return 0; // Not found
79 
80  KServiceGroup * newGroup = createGroup(offset, deep);
81 
82  // Check whether the dictionary was right.
83  if (newGroup && (newGroup->relPath() != _name))
84  {
85  // No it wasn't...
86  delete newGroup;
87  newGroup = 0; // Not found
88  }
89  return newGroup;
90 }
91 
92 KServiceGroup * KServiceGroupFactory::findBaseGroup(const TQString &_baseGroupName, bool deep)
93 {
94  if (!m_baseGroupDict) return 0; // Error!
95 
96  // Warning : this assumes we're NOT building a database
97  // But since findServiceByName isn't called in that case...
98  // [ see KServiceTypeFactory for how to do it if needed ]
99 
100  int offset = m_baseGroupDict->find_string( _baseGroupName );
101  if (!offset) return 0; // Not found
102 
103  KServiceGroup * newGroup = createGroup(offset, deep);
104 
105  // Check whether the dictionary was right.
106  if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
107  {
108  // No it wasn't...
109  delete newGroup;
110  newGroup = 0; // Not found
111  }
112  return newGroup;
113 }
114 
115 KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep)
116 {
117  KServiceGroup * newEntry = 0L;
118  KSycocaType type;
119  TQDataStream *str = KSycoca::self()->findEntry(offset, type);
120  switch(type)
121  {
122  case KST_KServiceGroup:
123  newEntry = new KServiceGroup(*str, offset, deep);
124  break;
125 
126  default:
127  kdError(7011) << TQString(TQString("KServiceGroupFactory: unexpected object entry in KSycoca database (type = %1)").arg((int)type)) << endl;
128  return 0;
129  }
130  if (!newEntry->isValid())
131  {
132  kdError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!\n" << endl;
133  delete newEntry;
134  newEntry = 0;
135  }
136  return newEntry;
137 }
138 
139 KServiceGroup* KServiceGroupFactory::createEntry(int offset)
140 {
141  return createGroup(offset, true);
142 }
143 
144 KServiceGroupFactory *KServiceGroupFactory::_self = 0;
145 
146 void KServiceGroupFactory::virtual_hook( int id, void* data )
147 { KSycocaFactory::virtual_hook( id, data ); }
148 
KServiceGroup
KServiceGroup represents a group of service, for example screensavers.
Definition: kservicegroup.h:68
KServiceGroup::baseGroupName
TQString baseGroupName() const
Returns a non-empty string if the group is a special base group.
Definition: kservicegroup.h:264
KServiceGroup::isValid
bool isValid() const
Checks whether the entry is valid, returns always true.
Definition: kservicegroup.h:104
KServiceGroup::relPath
virtual TQString relPath() const
Returns the relative path of the service group.
Definition: kservicegroup.h:116

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeio/tdeio

Skip menu "tdeio/tdeio"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdeio by doxygen 1.8.8
This website is maintained by Timothy Pearson.