KDED
kbuildservicegroupfactory.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 "kbuildservicegroupfactory.h"
00020 #include "ksycoca.h"
00021 #include "ksycocadict.h"
00022 #include "kresourcelist.h"
00023 #include <kservicegroup_p.h>
00024
00025 #include <kglobal.h>
00026 #include <kstandarddirs.h>
00027 #include <kdebug.h>
00028 #include <klocale.h>
00029 #include <assert.h>
00030 #include <QtCore/QHash>
00031
00032 KBuildServiceGroupFactory::KBuildServiceGroupFactory() :
00033 KServiceGroupFactory()
00034 {
00035 m_resourceList = new KSycocaResourceList;
00036
00037
00038 m_baseGroupDict = new KSycocaDict();
00039 }
00040
00041
00042
00043 QStringList KBuildServiceGroupFactory::resourceTypes()
00044 {
00045 return QStringList();
00046 }
00047
00048 KBuildServiceGroupFactory::~KBuildServiceGroupFactory()
00049 {
00050 delete m_resourceList;
00051 }
00052
00053 KServiceGroup *
00054 KBuildServiceGroupFactory::createEntry( const QString&, const char * ) const
00055 {
00056
00057 kWarning("!!!! KBuildServiceGroupFactory::createEntry called!");
00058 return 0;
00059 }
00060
00061
00062 void KBuildServiceGroupFactory::addNewEntryTo( const QString &menuName, const KService::Ptr& newEntry)
00063 {
00064 KSycocaEntry::Ptr ptr = m_entryDict->value(menuName);
00065 KServiceGroup::Ptr entry;
00066 if (ptr && ptr->isType(KST_KServiceGroup))
00067 entry = KServiceGroup::Ptr::staticCast( ptr );
00068
00069 if (!entry)
00070 {
00071 kWarning(7021) << "KBuildServiceGroupFactory::addNewEntryTo( " << menuName << ", " << newEntry->name() << " ): menu does not exists!";
00072 return;
00073 }
00074 entry->addEntry( KSycocaEntry::Ptr::staticCast( newEntry ) );
00075 }
00076
00077 KServiceGroup::Ptr
00078 KBuildServiceGroupFactory::addNew( const QString &menuName, const QString& file, KServiceGroup::Ptr entry, bool isDeleted)
00079 {
00080 KSycocaEntry::Ptr ptr = m_entryDict->value(menuName);
00081 if (ptr)
00082 {
00083 kWarning(7021) << "KBuildServiceGroupFactory::addNew( " << menuName << ", " << file << " ): menu already exists!";
00084 return KServiceGroup::Ptr::staticCast( ptr );
00085 }
00086
00087
00088 if (!entry)
00089 entry = new KServiceGroup(file, menuName);
00090
00091 entry->d_func()->m_childCount = -1;
00092
00093 addEntry( KSycocaEntry::Ptr::staticCast(entry) );
00094
00095 if (menuName != "/")
00096 {
00097
00098 QString parent = menuName.left(menuName.length()-1);
00099 int i = parent.lastIndexOf('/');
00100 if (i > 0) {
00101 parent = parent.left(i+1);
00102 } else {
00103 parent = "/";
00104 }
00105
00106
00107 KServiceGroup::Ptr parentEntry;
00108 ptr = m_entryDict->value(parent);
00109 if (ptr && ptr->isType(KST_KServiceGroup))
00110 parentEntry = KServiceGroup::Ptr::staticCast( ptr );
00111 if (!parentEntry)
00112 {
00113 kWarning(7021) << "KBuildServiceGroupFactory::addNew( " << menuName << ", " << file << " ): parent menu does not exist!";
00114 }
00115 else
00116 {
00117 if (!isDeleted && !entry->isDeleted())
00118 parentEntry->addEntry( KSycocaEntry::Ptr::staticCast( entry ) );
00119 }
00120 }
00121 return entry;
00122 }
00123
00124 void
00125 KBuildServiceGroupFactory::addNewChild( const QString &parent, const KSycocaEntry::Ptr& newEntry)
00126 {
00127 QString name = "#parent#"+parent;
00128
00129 KServiceGroup::Ptr entry;
00130 KSycocaEntry::Ptr ptr = m_entryDict->value(name);
00131 if (ptr && ptr->isType(KST_KServiceGroup))
00132 entry = KServiceGroup::Ptr::staticCast( ptr );
00133
00134 if (!entry)
00135 {
00136 entry = new KServiceGroup(name);
00137 addEntry( KSycocaEntry::Ptr::staticCast( entry ) );
00138 }
00139 if (newEntry)
00140 entry->addEntry( newEntry );
00141 }
00142
00143 void
00144 KBuildServiceGroupFactory::addEntry( const KSycocaEntry::Ptr& newEntry)
00145 {
00146 KSycocaFactory::addEntry(newEntry);
00147
00148 KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( newEntry );
00149 serviceGroup->d_func()->m_serviceList.clear();
00150
00151 if ( !serviceGroup->baseGroupName().isEmpty() )
00152 {
00153 m_baseGroupDict->add( serviceGroup->baseGroupName(), newEntry );
00154 }
00155 }
00156
00157 void
00158 KBuildServiceGroupFactory::saveHeader(QDataStream &str)
00159 {
00160 KSycocaFactory::saveHeader(str);
00161
00162 str << (qint32) m_baseGroupDictOffset;
00163 }
00164
00165 void
00166 KBuildServiceGroupFactory::save(QDataStream &str)
00167 {
00168 KSycocaFactory::save(str);
00169
00170 m_baseGroupDictOffset = str.device()->pos();
00171 m_baseGroupDict->save(str);
00172
00173 int endOfFactoryData = str.device()->pos();
00174
00175
00176 saveHeader(str);
00177
00178
00179 str.device()->seek(endOfFactoryData);
00180 }
00181
00182 KServiceGroup::Ptr KBuildServiceGroupFactory::findGroupByDesktopPath( const QString &_name, bool deep )
00183 {
00184 assert (KSycoca::self()->isBuilding());
00185 Q_UNUSED(deep);
00186
00187 KSycocaEntry::Ptr group = m_entryDict->value( _name );
00188 return KServiceGroup::Ptr::staticCast( group );
00189 }