• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDECore

kservicegroupfactory.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE libraries
00002  *  Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License version 2 as published by the Free Software Foundation;
00007  *
00008  *  This library is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  *  Library General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU Library General Public License
00014  *  along with this library; see the file COPYING.LIB.  If not, write to
00015  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016  *  Boston, MA 02110-1301, USA.
00017  **/
00018 
00019 #include "kservicegroupfactory.h"
00020 #include "ksycoca.h"
00021 #include "ksycocatype.h"
00022 #include "ksycocadict.h"
00023 #include "kservice.h"
00024 
00025 #include <QtCore/QCharRef>
00026 
00027 #include <klocale.h>
00028 #include <kdebug.h>
00029 #include <kglobal.h>
00030 #include <kstandarddirs.h>
00031 
00032 KServiceGroupFactory::KServiceGroupFactory()
00033  : KSycocaFactory( KST_KServiceGroupFactory )
00034 {
00035    m_baseGroupDictOffset = 0;
00036    if (m_str)
00037    {
00038       // Read Header
00039       qint32 i;
00040       (*m_str) >> i;
00041       m_baseGroupDictOffset = i;
00042 
00043       const int saveOffset = m_str->device()->pos();
00044       // Init index tables
00045       m_baseGroupDict = new KSycocaDict(m_str, m_baseGroupDictOffset);
00046       m_str->device()->seek(saveOffset);
00047    }
00048    else
00049    {
00050       // Build new database
00051       m_baseGroupDict = new KSycocaDict();
00052    }
00053    _self = this;
00054 }
00055 
00056 KServiceGroupFactory::~KServiceGroupFactory()
00057 {
00058    _self = 0L;
00059    delete m_baseGroupDict;
00060 }
00061 
00062 KServiceGroupFactory * KServiceGroupFactory::self()
00063 {
00064   if (!_self)
00065     _self = new KServiceGroupFactory();
00066   return _self;
00067 }
00068 
00069 KServiceGroup::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
00070 {
00071    if (!sycocaDict()) return KServiceGroup::Ptr(); // Error!
00072    int offset = sycocaDict()->find_string( _name );
00073    if (!offset) return KServiceGroup::Ptr(); // Not found
00074 
00075    KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00076 
00077    // Check whether the dictionary was right.
00078    if (newGroup && (newGroup->relPath() != _name))
00079    {
00080       // No it wasn't...
00081       newGroup = 0; // Not found
00082    }
00083    return newGroup;
00084 }
00085 
00086 KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
00087 {
00088    if (!m_baseGroupDict) return KServiceGroup::Ptr(); // Error!
00089 
00090    // Warning : this assumes we're NOT building a database
00091    // But since findBaseGroup isn't called in that case...
00092    // [ see KServiceTypeFactory for how to do it if needed ]
00093 
00094    int offset = m_baseGroupDict->find_string( _baseGroupName );
00095    if (!offset) return KServiceGroup::Ptr(); // Not found
00096 
00097    KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00098 
00099    // Check whether the dictionary was right.
00100    if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
00101    {
00102       // No it wasn't...
00103       newGroup = 0; // Not found
00104    }
00105    return newGroup;
00106 }
00107 
00108 KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep) const
00109 {
00110    KServiceGroup * newEntry = 0L;
00111    KSycocaType type;
00112    QDataStream *str = KSycoca::self()->findEntry(offset, type);
00113    switch(type)
00114    {
00115      case KST_KServiceGroup:
00116         newEntry = new KServiceGroup(*str, offset, deep);
00117         break;
00118 
00119      default:
00120         kError(7011) << QString("KServiceGroupFactory: unexpected object entry in KSycoca database (type = %1)").arg((int)type) << endl;
00121         return 0;
00122    }
00123    if (!newEntry->isValid())
00124    {
00125       kError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!\n" << endl;
00126       delete newEntry;
00127       newEntry = 0;
00128    }
00129    return newEntry;
00130 }
00131 
00132 KServiceGroup* KServiceGroupFactory::createEntry(int offset) const
00133 {
00134    return createGroup(offset, true);
00135 }
00136 
00137 KServiceGroupFactory *KServiceGroupFactory::_self = 0;
00138 
00139 void KServiceGroupFactory::virtual_hook( int id, void* data )
00140 { KSycocaFactory::virtual_hook( id, data ); }
00141 

KDECore

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal