kservicegroupfactory.cpp
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
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       
00039       Q_INT32 i;
00040       (*m_str) >> i;
00041       m_baseGroupDictOffset = i;
00042 
00043       int saveOffset = m_str->device()->at();
00044       
00045       m_baseGroupDict = new KSycocaDict(m_str, m_baseGroupDictOffset);
00046       m_str->device()->at(saveOffset);
00047    }
00048    else
00049    {
00050       
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; 
00072 
00073    
00074    
00075    
00076 
00077    int offset = m_sycocaDict->find_string( _name );
00078    if (!offset) return 0; 
00079 
00080    KServiceGroup * newGroup = createGroup(offset, deep);
00081 
00082    
00083    if (newGroup && (newGroup->relPath() != _name))
00084    {
00085       
00086       delete newGroup;
00087       newGroup = 0; 
00088    }
00089    return newGroup;
00090 }
00091 
00092 KServiceGroup * KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
00093 {
00094    if (!m_baseGroupDict) return 0; 
00095 
00096    
00097    
00098    
00099 
00100    int offset = m_baseGroupDict->find_string( _baseGroupName );
00101    if (!offset) return 0; 
00102 
00103    KServiceGroup * newGroup = createGroup(offset, deep);
00104 
00105    
00106    if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
00107    {
00108       
00109       delete newGroup;
00110       newGroup = 0; 
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.2.0.