• Skip to content
  • Skip to link menu
KDE 4.3 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 K_GLOBAL_STATIC(KSycocaFactorySingleton<KServiceGroupFactory>, kServiceGroupFactoryInstance)
00033 
00034 KServiceGroupFactory::KServiceGroupFactory()
00035     : KSycocaFactory( KST_KServiceGroupFactory )
00036 {
00037     kServiceGroupFactoryInstance->instanceCreated(this);
00038     m_baseGroupDictOffset = 0;
00039     if (!KSycoca::self()->isBuilding()) {
00040         QDataStream* str = stream();
00041         // Read Header
00042         qint32 i;
00043         (*str) >> i;
00044         m_baseGroupDictOffset = i;
00045 
00046         const int saveOffset = str->device()->pos();
00047         // Init index tables
00048         m_baseGroupDict = new KSycocaDict(str, m_baseGroupDictOffset);
00049         str->device()->seek(saveOffset);
00050     }
00051 }
00052 
00053 KServiceGroupFactory::~KServiceGroupFactory()
00054 {
00055     delete m_baseGroupDict;
00056     if (kServiceGroupFactoryInstance.exists())
00057         kServiceGroupFactoryInstance->instanceDestroyed(this);
00058 }
00059 
00060 KServiceGroupFactory * KServiceGroupFactory::self()
00061 {
00062     return kServiceGroupFactoryInstance->self();
00063 }
00064 
00065 KServiceGroup::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
00066 {
00067    if (!sycocaDict()) return KServiceGroup::Ptr(); // Error!
00068    int offset = sycocaDict()->find_string( _name );
00069    if (!offset) return KServiceGroup::Ptr(); // Not found
00070 
00071    KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00072 
00073    // Check whether the dictionary was right.
00074    if (newGroup && (newGroup->relPath() != _name))
00075    {
00076       // No it wasn't...
00077       newGroup = 0; // Not found
00078    }
00079    return newGroup;
00080 }
00081 
00082 KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
00083 {
00084    if (!m_baseGroupDict) return KServiceGroup::Ptr(); // Error!
00085 
00086    // Warning : this assumes we're NOT building a database
00087    // But since findBaseGroup isn't called in that case...
00088    // [ see KServiceTypeFactory for how to do it if needed ]
00089 
00090    int offset = m_baseGroupDict->find_string( _baseGroupName );
00091    if (!offset) return KServiceGroup::Ptr(); // Not found
00092 
00093    KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00094 
00095    // Check whether the dictionary was right.
00096    if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
00097    {
00098       // No it wasn't...
00099       newGroup = 0; // Not found
00100    }
00101    return newGroup;
00102 }
00103 
00104 KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep) const
00105 {
00106    KServiceGroup * newEntry = 0L;
00107    KSycocaType type;
00108    QDataStream *str = KSycoca::self()->findEntry(offset, type);
00109    switch(type)
00110    {
00111      case KST_KServiceGroup:
00112         newEntry = new KServiceGroup(*str, offset, deep);
00113         break;
00114 
00115      default:
00116         kError(7011) << QString("KServiceGroupFactory: unexpected object entry in KSycoca database (type = %1)").arg((int)type) << endl;
00117         return 0;
00118    }
00119    if (!newEntry->isValid())
00120    {
00121       kError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!\n" << endl;
00122       delete newEntry;
00123       newEntry = 0;
00124    }
00125    return newEntry;
00126 }
00127 
00128 KServiceGroup* KServiceGroupFactory::createEntry(int offset) const
00129 {
00130    return createGroup(offset, true);
00131 }
00132 
00133 void KServiceGroupFactory::virtual_hook( int id, void* data )
00134 { KSycocaFactory::virtual_hook( id, data ); }
00135 

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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