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 KServiceGroupFactory::KServiceGroupFactory()
00033 : KSycocaFactory( KST_KServiceGroupFactory )
00034 {
00035 m_baseGroupDictOffset = 0;
00036 if (m_str)
00037 {
00038
00039 qint32 i;
00040 (*m_str) >> i;
00041 m_baseGroupDictOffset = i;
00042
00043 const int saveOffset = m_str->device()->pos();
00044
00045 m_baseGroupDict = new KSycocaDict(m_str, m_baseGroupDictOffset);
00046 m_str->device()->seek(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::Ptr KServiceGroupFactory::findGroupByDesktopPath(const QString &_name, bool deep)
00070 {
00071 if (!sycocaDict()) return KServiceGroup::Ptr();
00072 int offset = sycocaDict()->find_string( _name );
00073 if (!offset) return KServiceGroup::Ptr();
00074
00075 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00076
00077
00078 if (newGroup && (newGroup->relPath() != _name))
00079 {
00080
00081 newGroup = 0;
00082 }
00083 return newGroup;
00084 }
00085
00086 KServiceGroup::Ptr KServiceGroupFactory::findBaseGroup(const QString &_baseGroupName, bool deep)
00087 {
00088 if (!m_baseGroupDict) return KServiceGroup::Ptr();
00089
00090
00091
00092
00093
00094 int offset = m_baseGroupDict->find_string( _baseGroupName );
00095 if (!offset) return KServiceGroup::Ptr();
00096
00097 KServiceGroup::Ptr newGroup(createGroup(offset, deep));
00098
00099
00100 if (newGroup && (newGroup->baseGroupName() != _baseGroupName))
00101 {
00102
00103 newGroup = 0;
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