KDECore
kservicegroupfactory.cpp
Go to the documentation of this file.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 <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
00042 qint32 i;
00043 (*str) >> i;
00044 m_baseGroupDictOffset = i;
00045
00046 const int saveOffset = str->device()->pos();
00047
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();
00068 int offset = sycocaDict()->find_string( _name );
00069 if (!offset) return KServiceGroup::Ptr();
00070
00071 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00072
00073
00074 if (newGroup && (newGroup->relPath() != _name))
00075 {
00076
00077 newGroup = 0;
00078 }
00079 return newGroup;
00080 }
00081
00082 KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
00083 {
00084 if (!m_baseGroupDict) return KServiceGroup::Ptr();
00085
00086
00087
00088
00089
00090 int offset = m_baseGroupDict->find_string( _baseGroupName );
00091 if (!offset) return KServiceGroup::Ptr();
00092
00093 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00094
00095
00096 if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
00097 {
00098
00099 newGroup = 0;
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