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