KDED
kbuildservicegroupfactory.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 * Copyright (C) 2000 Waldo Bastian <bastian@kde.org> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Library General Public 00006 * License version 2 as published by the Free Software Foundation. 00007 * 00008 * This library is distributed in the hope that it will be useful, 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 * Library General Public License for more details. 00012 * 00013 * You should have received a copy of the GNU Library General Public License 00014 * along with this library; see the file COPYING.LIB. If not, write to 00015 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 * Boston, MA 02110-1301, USA. 00017 **/ 00018 00019 #include "kbuildservicegroupfactory.h" 00020 #include "ksycoca.h" 00021 #include "ksycocadict_p.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 // m_resourceList->add( "apps", "*.directory" ); 00037 00038 m_baseGroupDict = new KSycocaDict(); 00039 } 00040 00041 // return all service types for this factory 00042 // i.e. first arguments to m_resourceList->add() above 00043 QStringList KBuildServiceGroupFactory::resourceTypes() 00044 { 00045 return QStringList(); // << "apps"; 00046 } 00047 00048 KBuildServiceGroupFactory::~KBuildServiceGroupFactory() 00049 { 00050 delete m_resourceList; 00051 } 00052 00053 KServiceGroup * 00054 KBuildServiceGroupFactory::createEntry( const QString&, const char * ) const 00055 { 00056 // Unused 00057 kWarning(7021) << "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) << "( " << 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) << "( " << menuName << ", " << file << " ): menu already exists!"; 00084 return KServiceGroup::Ptr::staticCast( ptr ); 00085 } 00086 00087 // Create new group entry 00088 if (!entry) 00089 entry = new KServiceGroup(file, menuName); 00090 00091 entry->d_func()->m_childCount = -1; // Recalculate 00092 00093 addEntry( KSycocaEntry::Ptr::staticCast(entry) ); 00094 00095 if (menuName != "/") 00096 { 00097 // Make sure parent dir exists. 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) << "( " << 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 // Update header (pass #3) 00176 saveHeader(str); 00177 00178 // Seek to end. 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 // We're building a database - the service type must be in memory 00187 KSycocaEntry::Ptr group = m_entryDict->value( _name ); 00188 return KServiceGroup::Ptr::staticCast( group ); 00189 }
KDE 4.6 API Reference