• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • 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 #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 
00039 // return all service types for this factory
00040 // i.e. first arguments to m_resourceList->add() above
00041 QStringList KBuildServiceGroupFactory::resourceTypes()
00042 {
00043     return QStringList(); // << "apps";
00044 }
00045 
00046 KBuildServiceGroupFactory::~KBuildServiceGroupFactory()
00047 {
00048    delete m_resourceList;
00049 }
00050 
00051 KServiceGroup *
00052 KBuildServiceGroupFactory::createEntry( const QString&, const char * ) const
00053 {
00054   // Unused
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   // Create new group entry
00086   if (!entry)
00087      entry = new KServiceGroup(file, menuName);
00088 
00089   entry->d_func()->m_childCount = -1; // Recalculate
00090 
00091   addEntry( KSycocaEntry::Ptr::staticCast(entry) );
00092 
00093   if (menuName != "/")
00094   {
00095      // Make sure parent dir exists.
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    // Update header (pass #3)
00173    saveHeader(str);
00174 
00175    // Seek to end.
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     // We're building a database - the service type must be in memory
00184     KSycocaEntry::Ptr group = m_entryDict->value( _name );
00185     return KServiceGroup::Ptr::staticCast( group );
00186 }

KDED

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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