20 #include "kbuildservicefactory.h"
21 #include "tdesycoca.h"
22 #include "tdesycocadict.h"
23 #include "kresourcelist.h"
24 #include "kmimetype.h"
26 #include <tdeglobal.h>
27 #include <kstandarddirs.h>
28 #include <kmessageboxwrapper.h>
29 #include <tdelocale.h>
38 m_serviceTypeFactory( serviceTypeFactory ),
39 m_serviceGroupFactory( serviceGroupFactory )
41 m_resourceList =
new KSycocaResourceList();
44 m_resourceList->add(
"services",
"*.desktop" );
45 m_resourceList->add(
"services",
"*.kdelnk" );
52 return TQStringList() <<
"apps" <<
"services";
55 KBuildServiceFactory::~KBuildServiceFactory()
57 delete m_resourceList;
60 KService * KBuildServiceFactory::findServiceByName(
const TQString &_name)
62 return m_serviceDict[_name];
70 int pos = name.findRev(
'/');
73 name = name.mid(pos+1);
80 if (!name.endsWith(
".desktop") && !name.endsWith(
".kdelnk"))
83 KDesktopFile desktopFile(file,
true, resource);
85 KService * serv =
new KService( &desktopFile );
87 if ( serv->isValid() && !serv->isDeleted() )
91 if (!serv->isDeleted())
92 kdWarning(7012) <<
"Invalid Service : " << file << endl;
102 KSycocaFactory::saveHeader(str);
104 str << (TQ_INT32) m_nameDictOffset;
105 str << (TQ_INT32) m_relNameDictOffset;
106 str << (TQ_INT32) m_offerListOffset;
107 str << (TQ_INT32) m_initListOffset;
108 str << (TQ_INT32) m_menuIdDictOffset;
114 KSycocaFactory::save(str);
116 m_nameDictOffset = str.device()->at();
117 m_nameDict->save(str);
119 m_relNameDictOffset = str.device()->at();
120 m_relNameDict->save(str);
125 m_menuIdDictOffset = str.device()->at();
126 m_menuIdDict->save(str);
128 int endOfFactoryData = str.device()->at();
135 str.device()->at(endOfFactoryData);
139 KBuildServiceFactory::saveOfferList(TQDataStream &str)
141 m_offerListOffset = str.device()->at();
144 for(TQDictIterator<KSycocaEntry::Ptr> itserv ( *m_entryDict );
148 KService *service = (KService *) ((KSycocaEntry *)(*itserv.current()));
149 TQStringList serviceTypeList = service->serviceTypes();
150 KServiceType::List serviceTypes;
151 TQStringList::ConstIterator it = serviceTypeList.begin();
152 for( ; it != serviceTypeList.end(); ++it )
154 (*it).toInt(&isNumber);
158 KServiceType::Ptr serviceType = KServiceType::serviceType(*it);
164 serviceTypes.append(serviceType);
167 while(serviceTypes.count())
169 KServiceType::Ptr serviceType = serviceTypes.first();
170 serviceTypes.pop_front();
172 KServiceType::Ptr parentType = serviceType->parentType();
174 serviceTypes.append(parentType);
176 serviceType->addService(service);
181 for(TQDictIterator<KSycocaEntry::Ptr> it ( *(m_serviceTypeFactory->entryDict()) );
186 KServiceType *entry =
static_cast<KServiceType*
>(
static_cast<KSycocaEntry*
>(*it.current()));
187 KService::List services = entry->services();
189 for(KService::List::ConstIterator it2 = services.begin();
190 it2 != services.end(); ++it2)
192 KService *service = *it2;
193 str << (TQ_INT32) entry->offset();
194 str << (TQ_INT32) service->offset();
202 KBuildServiceFactory::saveInitList(TQDataStream &str)
204 m_initListOffset = str.device()->at();
206 KService::List initList;
208 for(TQDictIterator<KSycocaEntry::Ptr> itserv ( *m_entryDict );
212 KService::Ptr service = (KService *) ((KSycocaEntry *) *itserv.current());
213 if ( !service->init().isEmpty() )
215 initList.append(service);
218 str << (TQ_INT32) initList.count();
219 for(KService::List::Iterator it = initList.begin();
220 it != initList.end();
223 str << (TQ_INT32) (*it)->offset();
230 if (m_dupeDict.find(newEntry))
233 KSycocaFactory::addEntry(newEntry, resource);
235 KService * service = (KService *) newEntry;
236 m_dupeDict.insert(newEntry, service);
238 if (!service->isDeleted())
240 TQString parent = service->parentApp();
241 if (!parent.isEmpty())
242 m_serviceGroupFactory->
addNewChild(parent, resource, service);
245 TQString name = service->desktopEntryName();
246 m_nameDict->add( name, newEntry );
247 m_serviceDict.replace(name, service);
249 TQString relName = service->desktopEntryPath();
250 m_relNameDict->add( relName, newEntry );
251 TQString menuId = service->menuId();
252 if (!menuId.isEmpty())
253 m_menuIdDict->add( menuId, newEntry );
KBuildServiceFactory(KSycocaFactory *serviceTypeFactory, KBuildServiceGroupFactory *serviceGroupFactory)
Create factory.
virtual void save(TQDataStream &str)
Write out service specific index files.
static TQStringList resourceTypes()
Returns all resource types for this service factory.
void addEntry(KSycocaEntry *newEntry, const char *resource)
Add a new entry.
virtual void saveHeader(TQDataStream &str)
Write out header information.
virtual KSycocaEntry * createEntry(const TQString &file, const char *resource)
Construct a KService from a config file.
Service group factory for building tdesycoca.
KServiceGroup * addNewChild(const TQString &parent, const char *resource, KSycocaEntry *newEntry)
Adds the entry newEntry to the "parent group" parent, creating the group if necassery.