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