# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kservicegroupfactory.cpp

    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., 59 Temple Place - Suite 330,
    00016  *  Boston, MA 02111-1307, 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 <qstring.h>
    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       Q_INT32 i;
    00040       (*m_str) >> i;
    00041       m_baseGroupDictOffset = i;
    00042
    00043       int saveOffset = m_str->device()->at();
    00044       // Init index tables
    00045       m_baseGroupDict = new KSycocaDict(m_str, m_baseGroupDictOffset);
    00046       m_str->device()->at(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 * KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
    00070 {
    00071    if (!m_sycocaDict) return 0; // Error!
    00072
    00073    // Warning : this assumes we're NOT building a database
    00074    // But since findServiceByName isn't called in that case...
    00075    // [ see KServiceTypeFactory for how to do it if needed ]
    00076
    00077    int offset = m_sycocaDict->find_string( _name );
    00078    if (!offset) return 0; // Not found
    00079
    00080    KServiceGroup * newGroup = createGroup(offset, deep);
    00081
    00082    // Check whether the dictionary was right.
    00083    if (newGroup && (newGroup->relPath() != _name))
    00084    {
    00085       // No it wasn't...
    00086       delete newGroup;
    00087       newGroup = 0; // Not found
    00088    }
    00089    return newGroup;
    00090 }
    00091
    00092 KServiceGroup * KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
    00093 {
    00094    if (!m_baseGroupDict) return 0; // Error!
    00095
    00096    // Warning : this assumes we're NOT building a database
    00097    // But since findServiceByName isn't called in that case...
    00098    // [ see KServiceTypeFactory for how to do it if needed ]
    00099
    00100    int offset = m_baseGroupDict->find_string( _baseGroupName );
    00101    if (!offset) return 0; // Not found
    00102
    00103    KServiceGroup * newGroup = createGroup(offset, deep);
    00104
    00105    // Check whether the dictionary was right.
    00106    if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
    00107    {
    00108       // No it wasn't...
    00109       delete newGroup;
    00110       newGroup = 0; // Not found
    00111    }
    00112    return newGroup;
    00113 }
    00114
    00115 KServiceGroup* KServiceGroupFactory::createGroup(int offset, bool deep)
    00116 {
    00117    KServiceGroup * newEntry = 0L;
    00118    KSycocaType type;
    00119    QDataStream *str = KSycoca::self()->findEntry(offset, type);
    00120    switch(type)
    00121    {
    00122      case KST_KServiceGroup:
    00123         newEntry = new KServiceGroup(*str, offset, deep);
    00124         break;
    00125
    00126      default:
    00127         kdError(7011) << QString("KServiceGroupFactory: unexpected object entry in KSycoca database (type = %1)").arg((int)type) << endl;
    00128         return 0;
    00129    }
    00130    if (!newEntry->isValid())
    00131    {
    00132       kdError(7011) << "KServiceGroupFactory: corrupt object in KSycoca database!\n" << endl;
    00133       delete newEntry;
    00134       newEntry = 0;
    00135    }
    00136    return newEntry;
    00137 }
    00138
    00139 KServiceGroup* KServiceGroupFactory::createEntry(int offset)
    00140 {
    00141    return createGroup(offset, true);
    00142 }
    00143
    00144 KServiceGroupFactory *KServiceGroupFactory::_self = 0;
    00145
    00146 void KServiceGroupFactory::virtual_hook( int id, void* data )
    00147 { KSycocaFactory::virtual_hook( id, data ); }
    00148

This file is part of the documentation for kio Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:24:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003