• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

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.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 //   m_resourceList->add( "apps", "*.directory" );
00036 }
00037 
00038 // return all service types for this factory
00039 // i.e. first arguments to m_resourceList->add() above
00040 QStringList KBuildServiceGroupFactory::resourceTypes()
00041 {
00042     return QStringList(); // << "apps";
00043 }
00044 
00045 KBuildServiceGroupFactory::~KBuildServiceGroupFactory()
00046 {
00047    delete m_resourceList;
00048 }
00049 
00050 KServiceGroup *
00051 KBuildServiceGroupFactory::createEntry( const QString&, const char * )
00052 {
00053   // Unused
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   // Create new group entry
00085   if (!entry)
00086      entry = new KServiceGroup(file, menuName);
00087      
00088   entry->m_childCount = -1; // Recalculate
00089 
00090   addEntry( entry, "apps" ); // "vfolder" ??
00091 
00092   if (menuName != "/")
00093   {
00094      // Make sure parent dir exists.
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    // Update header (pass #3)
00174    saveHeader(str);
00175 
00176    // Seek to end.
00177    str.device()->at(endOfFactoryData);
00178 }

KDED

Skip menu "KDED"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal