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

KDECore

kservicegroup.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 3 -*-
00002 /*  This file is part of the KDE libraries
00003  *  Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation;
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kservicegroup.h"
00021 #include "kservicegroup_p.h"
00022 #include "kservicefactory.h"
00023 #include "kservicegroupfactory.h"
00024 #include "kservice.h"
00025 #include <ksycoca.h>
00026 #include <kglobal.h>
00027 #include <kstandarddirs.h>
00028 #include <klocale.h>
00029 #include <kdebug.h>
00030 #include <ksortablelist.h>
00031 #include <kdesktopfile.h>
00032 #include <kconfiggroup.h>
00033 
00034 
00035 KServiceGroup::KServiceGroup( const QString & name )
00036  : KSycocaEntry(*new KServiceGroupPrivate(name))
00037 {
00038 }
00039 
00040 KServiceGroup::KServiceGroup( const QString &configFile, const QString & _relpath )
00041  : KSycocaEntry(*new KServiceGroupPrivate(_relpath))
00042 {
00043     Q_D(KServiceGroup);
00044 
00045     QString cfg = configFile;
00046     if (cfg.isEmpty())
00047         cfg = _relpath + ".directory";
00048 
00049     d->load(cfg);
00050 }
00051 
00052 void KServiceGroupPrivate::load(const QString &cfg)
00053 {
00054   directoryEntryPath = cfg;
00055 
00056   const KDesktopFile desktopFile( cfg );
00057 
00058   const KConfigGroup config = desktopFile.desktopGroup();
00059 
00060   m_strCaption = config.readEntry( "Name" );
00061   m_strIcon = config.readEntry( "Icon" );
00062   m_strComment = config.readEntry( "Comment" );
00063   deleted = config.readEntry("Hidden", false );
00064   m_bNoDisplay = desktopFile.noDisplay();
00065   m_strBaseGroupName = config.readEntry( "X-KDE-BaseGroup" );
00066   suppressGenericNames = config.readEntry( "X-KDE-SuppressGenericNames", QStringList() );
00067 //  d->sortOrder = config.readEntry("SortOrder", QStringList());
00068 
00069   // Fill in defaults.
00070   if (m_strCaption.isEmpty())
00071   {
00072      m_strCaption = path;
00073      if (m_strCaption.endsWith(QLatin1Char('/')))
00074         m_strCaption = m_strCaption.left(m_strCaption.length()-1);
00075      int i = m_strCaption.lastIndexOf('/');
00076      if (i > 0)
00077         m_strCaption = m_strCaption.mid(i+1);
00078   }
00079   if (m_strIcon.isEmpty())
00080      m_strIcon = "folder";
00081 }
00082 
00083 KServiceGroup::KServiceGroup( QDataStream& _str, int offset, bool deep ) :
00084     KSycocaEntry(*new KServiceGroupPrivate(_str, offset))
00085 {
00086   Q_D(KServiceGroup);
00087   d->m_bDeep = deep;
00088   d->load( _str );
00089 }
00090 
00091 KServiceGroup::~KServiceGroup()
00092 {
00093 }
00094 
00095 QString KServiceGroup::relPath() const
00096 {
00097     return entryPath();
00098 }
00099 
00100 QString KServiceGroup::caption() const
00101 {
00102     Q_D(const KServiceGroup);
00103     return d->m_strCaption;
00104 }
00105 
00106 QString KServiceGroup::icon() const
00107 {
00108     Q_D(const KServiceGroup);
00109     return d->m_strIcon;
00110 }
00111 
00112 QString KServiceGroup::comment() const
00113 {
00114     Q_D(const KServiceGroup);
00115     return d->m_strComment;
00116 }
00117 
00118 int KServiceGroup::childCount() const
00119 {
00120     Q_D(const KServiceGroup);
00121     return d->childCount();
00122 }
00123 
00124 int KServiceGroupPrivate::childCount() const
00125 {
00126   if (m_childCount == -1)
00127   {
00128      m_childCount = 0;
00129 
00130      for( KServiceGroup::List::ConstIterator it = m_serviceList.begin();
00131           it != m_serviceList.end(); ++it)
00132      {
00133         KSycocaEntry::Ptr p = *it;
00134         if (p->isType(KST_KService))
00135         {
00136             KService::Ptr service = KService::Ptr::staticCast( p );
00137            if (!service->noDisplay())
00138               m_childCount++;
00139         }
00140         else if (p->isType(KST_KServiceGroup))
00141         {
00142            KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( p );
00143            m_childCount += serviceGroup->childCount();
00144         }
00145      }
00146   }
00147   return m_childCount;
00148 }
00149 
00150 
00151 bool KServiceGroup::showInlineHeader() const
00152 {
00153     Q_D(const KServiceGroup);
00154     return d->m_bShowInlineHeader;
00155 }
00156 
00157 bool KServiceGroup::showEmptyMenu() const
00158 {
00159     Q_D(const KServiceGroup);
00160     return d->m_bShowEmptyMenu;
00161 }
00162 
00163 bool KServiceGroup::inlineAlias() const
00164 {
00165     Q_D(const KServiceGroup);
00166     return d->m_bInlineAlias;
00167 }
00168 
00169 void KServiceGroup::setInlineAlias(bool _b)
00170 {
00171     Q_D(KServiceGroup);
00172     d->m_bInlineAlias = _b;
00173 }
00174 
00175 void KServiceGroup::setShowEmptyMenu(bool _b)
00176 {
00177     Q_D(KServiceGroup);
00178     d->m_bShowEmptyMenu=_b;
00179 }
00180 
00181 void KServiceGroup::setShowInlineHeader(bool _b)
00182 {
00183     Q_D(KServiceGroup);
00184     d->m_bShowInlineHeader=_b;
00185 }
00186 
00187 int KServiceGroup::inlineValue() const
00188 {
00189     Q_D(const KServiceGroup);
00190     return d->m_inlineValue;
00191 }
00192 
00193 void KServiceGroup::setInlineValue(int _val)
00194 {
00195     Q_D(KServiceGroup);
00196     d->m_inlineValue = _val;
00197 }
00198 
00199 bool KServiceGroup::allowInline() const
00200 {
00201     Q_D(const KServiceGroup);
00202     return d->m_bAllowInline;
00203 }
00204 
00205 void KServiceGroup::setAllowInline(bool _b)
00206 {
00207     Q_D(KServiceGroup);
00208     d->m_bAllowInline = _b;
00209 }
00210 
00211 bool KServiceGroup::noDisplay() const
00212 {
00213     Q_D(const KServiceGroup);
00214   return d->m_bNoDisplay || d->m_strCaption.startsWith('.');
00215 }
00216 
00217 QStringList KServiceGroup::suppressGenericNames() const
00218 {
00219     Q_D(const KServiceGroup);
00220   return d->suppressGenericNames;
00221 }
00222 
00223 void KServiceGroupPrivate::load( QDataStream& s )
00224 {
00225   QStringList groupList;
00226   qint8 noDisplay;
00227   qint8 _showEmptyMenu;
00228   qint8 inlineHeader;
00229   qint8 _inlineAlias;
00230   qint8 _allowInline;
00231   s >> m_strCaption >> m_strIcon >>
00232       m_strComment >> groupList >> m_strBaseGroupName >> m_childCount >>
00233       noDisplay >> suppressGenericNames >> directoryEntryPath >>
00234       sortOrder >> _showEmptyMenu >> inlineHeader >> _inlineAlias >> _allowInline;
00235 
00236   m_bNoDisplay = (noDisplay != 0);
00237   m_bShowEmptyMenu = ( _showEmptyMenu != 0 );
00238   m_bShowInlineHeader = ( inlineHeader != 0 );
00239   m_bInlineAlias = ( _inlineAlias != 0 );
00240   m_bAllowInline = ( _allowInline != 0 );
00241 
00242   if (m_bDeep)
00243   {
00244      Q_FOREACH(const QString &path, groupList)
00245      {
00246         if ( path.endsWith( QLatin1Char( '/' ) ) )
00247         {
00248            KServiceGroup::Ptr serviceGroup;
00249            serviceGroup = KServiceGroupFactory::self()->findGroupByDesktopPath(path, false);
00250            if (serviceGroup)
00251                m_serviceList.append( KServiceGroup::SPtr::staticCast(serviceGroup) );
00252         }
00253         else
00254         {
00255            KService::Ptr service;
00256            service = KServiceFactory::self()->findServiceByDesktopPath(path);
00257            if (service)
00258               m_serviceList.append( KServiceGroup::SPtr::staticCast(service) );
00259         }
00260      }
00261   }
00262 }
00263 
00264 void KServiceGroup::addEntry( const KSycocaEntry::Ptr& entry)
00265 {
00266     Q_D(KServiceGroup);
00267   d->m_serviceList.append(entry);
00268 }
00269 
00270 void KServiceGroupPrivate::save( QDataStream& s )
00271 {
00272   KSycocaEntryPrivate::save( s );
00273 
00274   QStringList groupList;
00275   Q_FOREACH(KSycocaEntry::Ptr p, m_serviceList)
00276   {
00277      if (p->isType(KST_KService))
00278      {
00279         KService::Ptr service = KService::Ptr::staticCast( p );
00280         groupList.append( service->entryPath() );
00281      }
00282      else if (p->isType(KST_KServiceGroup))
00283      {
00284         KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( p );
00285         groupList.append( serviceGroup->relPath() );
00286      }
00287      else
00288      {
00289         //fprintf(stderr, "KServiceGroup: Unexpected object in list!\n");
00290      }
00291   }
00292 
00293   (void) childCount();
00294 
00295   qint8 noDisplay = m_bNoDisplay ? 1 : 0;
00296   qint8 _showEmptyMenu = m_bShowEmptyMenu ? 1 : 0;
00297   qint8 inlineHeader = m_bShowInlineHeader ? 1 : 0;
00298   qint8 _inlineAlias = m_bInlineAlias ? 1 : 0;
00299   qint8 _allowInline = m_bAllowInline ? 1 : 0;
00300   s << m_strCaption << m_strIcon <<
00301       m_strComment << groupList << m_strBaseGroupName << m_childCount <<
00302       noDisplay << suppressGenericNames << directoryEntryPath <<
00303       sortOrder <<_showEmptyMenu <<inlineHeader<<_inlineAlias<<_allowInline;
00304 }
00305 
00306 QList<KServiceGroup::Ptr> KServiceGroup::groupEntries(EntriesOptions options)
00307 {
00308     Q_D(KServiceGroup);
00309     bool sort = options & SortEntries || options & AllowSeparators;
00310     QList<KServiceGroup::Ptr> list;
00311     List tmp = d->entries(this, sort, options & ExcludeNoDisplay, options & AllowSeparators, options & SortByGenericName);
00312     foreach(const SPtr &ptr, tmp) {
00313         if (ptr->isType(KST_KServiceGroup))
00314             list.append(Ptr::staticCast(ptr));
00315         else if (ptr->isType(KST_KServiceSeparator))
00316             list.append(KServiceGroup::Ptr(static_cast<KServiceGroup *>(new KSycocaEntry())));
00317         else if (sort && ptr->isType(KST_KService))
00318             break;
00319     }
00320     return list;
00321 }
00322 
00323 KService::List KServiceGroup::serviceEntries(EntriesOptions options)
00324 {
00325     Q_D(KServiceGroup);
00326     bool sort = options & SortEntries || options & AllowSeparators;
00327     QList<KService::Ptr> list;
00328     List tmp = d->entries(this, sort, options & ExcludeNoDisplay, options & AllowSeparators, options & SortByGenericName);
00329     bool foundService = false;
00330     foreach(const SPtr &ptr, tmp) {
00331         if (ptr->isType(KST_KService)) {
00332             list.append(KService::Ptr::staticCast(ptr));
00333             foundService = true;
00334         }
00335         else if (ptr->isType(KST_KServiceSeparator) && foundService) {
00336             list.append(KService::Ptr(static_cast<KService *>(new KSycocaEntry())));
00337         }
00338     }
00339     return list;
00340 }
00341 
00342 KServiceGroup::List
00343 KServiceGroup::entries(bool sort)
00344 {
00345     Q_D(KServiceGroup);
00346     return d->entries(this, sort, true, false, false);
00347 }
00348 
00349 KServiceGroup::List
00350 KServiceGroup::entries(bool sort, bool excludeNoDisplay)
00351 {
00352     Q_D(KServiceGroup);
00353     return d->entries(this, sort, excludeNoDisplay, false, false);
00354 }
00355 
00356 KServiceGroup::List
00357 KServiceGroup::entries(bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
00358 {
00359     Q_D(KServiceGroup);
00360     return d->entries(this, sort, excludeNoDisplay, allowSeparators, sortByGenericName);
00361 }
00362 
00363 static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator)
00364 {
00365    if (addSeparator && !sorted.isEmpty())
00366       sorted.append(KSycocaEntry::Ptr(new KServiceSeparator()));
00367    sorted.append(p);
00368    addSeparator = false;
00369 }
00370 
00371 KServiceGroup::List
00372 KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
00373 {
00374     KServiceGroup::Ptr grp;
00375 
00376     // If the entries haven't been loaded yet, we have to reload ourselves
00377     // together with the entries. We can't only load the entries afterwards
00378     // since the offsets could have been changed if the database has changed.
00379 
00380     if (!m_bDeep) {
00381 
00382         grp = KServiceGroupFactory::self()->findGroupByDesktopPath(path, true);
00383 
00384         group = grp.data();
00385         if (0 == group) // No guarantee that we still exist!
00386             return KServiceGroup::List();
00387     }
00388 
00389     if (!sort)
00390         return group->d_func()->m_serviceList;
00391 
00392     // Sort the list alphabetically, according to locale.
00393     // Groups come first, then services.
00394 
00395     KSortableList<KServiceGroup::SPtr,QByteArray> slist;
00396     KSortableList<KServiceGroup::SPtr,QByteArray> glist;
00397     Q_FOREACH (KSycocaEntry::Ptr p, group->d_func()->m_serviceList)
00398     {
00399         bool noDisplay = p->isType(KST_KServiceGroup) ?
00400                                    static_cast<KServiceGroup *>(p.data())->noDisplay() :
00401                                    static_cast<KService *>(p.data())->noDisplay();
00402         if (excludeNoDisplay && noDisplay)
00403            continue;
00404         // Choose the right list
00405         KSortableList<KServiceGroup::SPtr,QByteArray> & list = p->isType(KST_KServiceGroup) ? glist : slist;
00406         QString name;
00407         if (p->isType(KST_KServiceGroup))
00408           name = static_cast<KServiceGroup *>(p.data())->caption();
00409         else if (sortByGenericName)
00410           name = static_cast<KService *>(p.data())->genericName() + ' ' + p->name();
00411         else
00412           name = p->name() + ' ' + static_cast<KService *>(p.data())->genericName();
00413 
00414         QByteArray key;
00415         // strxfrm() crashes on Solaris
00416 #ifndef USE_SOLARIS
00417         // maybe it'd be better to use wcsxfrm() where available
00418         key.resize( name.length() * 4 + 1 );
00419         size_t ln = strxfrm( key.data(), name.toLocal8Bit().data(), key.size());
00420         if( ln != size_t( -1 ))
00421         {
00422             if( (int)ln >= key.size())
00423             { // didn't fit?
00424                 key.resize( ln + 1 );
00425                 if( strxfrm( key.data(), name.toLocal8Bit().data(), key.size()) == size_t( -1 ))
00426                     key = name.toLocal8Bit();
00427             }
00428         }
00429         else
00430 #endif
00431         {
00432             key = name.toLocal8Bit();
00433         }
00434         list.insert(key,KServiceGroup::SPtr(p));
00435     }
00436     // Now sort
00437     slist.sort();
00438     glist.sort();
00439 
00440     if (sortOrder.isEmpty())
00441     {
00442        sortOrder << ":M";
00443        sortOrder << ":F";
00444        sortOrder << ":OIH IL[4]"; //just inline header
00445     }
00446 
00447     QString rp = path;
00448     if(rp == "/") rp.clear();
00449 
00450     // Iterate through the sort spec list.
00451     // If an entry gets mentioned explicitly, we remove it from the sorted list
00452     Q_FOREACH (const QString &item, sortOrder)
00453     {
00454         if (item.isEmpty()) continue;
00455         if (item[0] == '/')
00456         {
00457           QString groupPath = rp + item.mid(1) + '/';
00458            // Remove entry from sorted list of services.
00459           for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = glist.begin(); it2 != glist.end(); ++it2)
00460           {
00461              const KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( (*it2).value() );
00462              if (group->relPath() == groupPath)
00463              {
00464                 glist.erase(it2);
00465                 break;
00466              }
00467           }
00468         }
00469         else if (item[0] != ':')
00470         {
00471            // Remove entry from sorted list of services.
00472            // TODO: Remove item from sortOrder-list if not found
00473            // TODO: This prevents duplicates
00474           for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = slist.begin(); it2 != slist.end(); ++it2)
00475           {
00476              const KService::Ptr service = KService::Ptr::staticCast( (*it2).value() );
00477              if (service->menuId() == item)
00478              {
00479                 slist.erase(it2);
00480                 break;
00481              }
00482           }
00483         }
00484     }
00485 
00486     KServiceGroup::List sorted;
00487 
00488     bool needSeparator = false;
00489     // Iterate through the sort spec list.
00490     // Add the entries to the list according to the sort spec.
00491     for (QStringList::ConstIterator it(sortOrder.constBegin()); it != sortOrder.constEnd(); ++it)
00492     {
00493         const QString &item = *it;
00494         if (item.isEmpty()) continue;
00495         if (item[0] == ':')
00496         {
00497           // Special condition...
00498           if (item == ":S")
00499           {
00500              if (allowSeparators)
00501                 needSeparator = true;
00502           }
00503           else if ( item.contains( ":O" ) )
00504           {
00505               //todo parse attribute:
00506               QString tmp(  item );
00507               tmp = tmp.remove(":O");
00508               QStringList optionAttribute = tmp.split(' ', QString::SkipEmptyParts);
00509               if ( optionAttribute.isEmpty() )
00510                   optionAttribute.append( tmp );
00511               bool showEmptyMenu = false;
00512               bool showInline = false;
00513               bool showInlineHeader = false;
00514               bool showInlineAlias = false;
00515               int inlineValue = -1;
00516 
00517               for ( QStringList::Iterator it3 = optionAttribute.begin(); it3 != optionAttribute.end(); ++it3 )
00518               {
00519                   parseAttribute( *it3,  showEmptyMenu, showInline, showInlineHeader, showInlineAlias, inlineValue );
00520               }
00521               for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = glist.begin(); it2 != glist.end(); ++it2)
00522               {
00523                   KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( (*it2).value() );
00524                   group->setShowEmptyMenu(  showEmptyMenu  );
00525                   group->setAllowInline( showInline );
00526                   group->setShowInlineHeader( showInlineHeader );
00527                   group->setInlineAlias( showInlineAlias );
00528                   group->setInlineValue( inlineValue );
00529               }
00530 
00531           }
00532           else if (item == ":M")
00533           {
00534             // Add sorted list of sub-menus
00535             for(KSortableList<KServiceGroup::SPtr,QByteArray>::const_iterator it2 = glist.constBegin(); it2 != glist.constEnd(); ++it2)
00536             {
00537               addItem(sorted, (*it2).value(), needSeparator);
00538             }
00539           }
00540           else if (item == ":F")
00541           {
00542             // Add sorted list of services
00543             for(KSortableList<KServiceGroup::SPtr,QByteArray>::const_iterator it2 = slist.constBegin(); it2 != slist.constEnd(); ++it2)
00544             {
00545               addItem(sorted, (*it2).value(), needSeparator);
00546             }
00547           }
00548           else if (item == ":A")
00549           {
00550             // Add sorted lists of services and submenus
00551             KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it_s = slist.begin();
00552             KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it_g = glist.begin();
00553 
00554             while(true)
00555             {
00556                if (it_s == slist.end())
00557                {
00558                   if (it_g == glist.end())
00559                      break; // Done
00560 
00561                   // Insert remaining sub-menu
00562                   addItem(sorted, (*it_g).value(), needSeparator);
00563                   it_g++;
00564                }
00565                else if (it_g == glist.end())
00566                {
00567                   // Insert remaining service
00568                   addItem(sorted, (*it_s).value(), needSeparator);
00569                   it_s++;
00570                }
00571                else if ((*it_g).key() < (*it_s).key())
00572                {
00573                   // Insert sub-menu first
00574                   addItem(sorted, (*it_g).value(), needSeparator);
00575                   it_g++;
00576                }
00577                else
00578                {
00579                   // Insert service first
00580                   addItem(sorted, (*it_s).value(), needSeparator);
00581                   it_s++;
00582                }
00583             }
00584           }
00585         }
00586         else if (item[0] == '/')
00587         {
00588             QString groupPath = rp + item.mid(1) + '/';
00589 
00590             for (KServiceGroup::List::ConstIterator it2(group->d_func()->m_serviceList.constBegin());
00591                  it2 != group->d_func()->m_serviceList.constEnd(); ++it2)
00592             {
00593                 if (!(*it2)->isType(KST_KServiceGroup))
00594                     continue;
00595                 KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( *it2 );
00596                 if (group->relPath() == groupPath)
00597                 {
00598                     if (!excludeNoDisplay || !group->noDisplay())
00599                     {
00600                         ++it;
00601                         const QString &nextItem =
00602                             (it == sortOrder.constEnd()) ? QString() : *it;
00603 
00604                         if ( nextItem.startsWith( ":O" ) )
00605                         {
00606                             QString tmp( nextItem );
00607                             tmp = tmp.remove(":O");
00608                             QStringList optionAttribute = tmp.split(' ', QString::SkipEmptyParts);
00609                             if ( optionAttribute.isEmpty() )
00610                                 optionAttribute.append( tmp );
00611                             bool bShowEmptyMenu = false;
00612                             bool bShowInline = false;
00613                             bool bShowInlineHeader = false;
00614                             bool bShowInlineAlias = false;
00615                             int inlineValue = -1;
00616                             Q_FOREACH( const QString &opt_attr, optionAttribute )
00617                             {
00618                                 parseAttribute( opt_attr, bShowEmptyMenu, bShowInline, bShowInlineHeader, bShowInlineAlias , inlineValue );
00619                                 group->setShowEmptyMenu( bShowEmptyMenu );
00620                                 group->setAllowInline( bShowInline );
00621                                 group->setShowInlineHeader( bShowInlineHeader );
00622                                 group->setInlineAlias( bShowInlineAlias );
00623                                 group->setInlineValue( inlineValue );
00624                             }
00625                         }
00626                         else
00627                             it--;
00628 
00629                         addItem(sorted, KServiceGroup::SPtr::staticCast(group), needSeparator);
00630                     }
00631                     break;
00632                 }
00633             }
00634         }
00635         else
00636         {
00637             for (KServiceGroup::List::ConstIterator it2(group->d_func()->m_serviceList.constBegin());
00638                  it2 != group->d_func()->m_serviceList.constEnd(); ++it2)
00639             {
00640                 if (!(*it2)->isType(KST_KService))
00641                     continue;
00642                 const KService::Ptr service = KService::Ptr::staticCast( *it2 );
00643                 if (service->menuId() == item)
00644                 {
00645                     if (!excludeNoDisplay || !service->noDisplay())
00646                         addItem(sorted, (*it2), needSeparator);
00647                     break;
00648                 }
00649             }
00650         }
00651     }
00652 
00653     return sorted;
00654 }
00655 
00656 void KServiceGroupPrivate::parseAttribute( const QString &item ,  bool &showEmptyMenu, bool &showInline, bool &showInlineHeader, bool & showInlineAlias , int &inlineValue )
00657 {
00658     if( item == "ME") //menu empty
00659         showEmptyMenu=true;
00660     else if ( item == "NME") //not menu empty
00661         showEmptyMenu=false;
00662     else if( item == "I") //inline menu !
00663         showInline = true;
00664     else if ( item == "NI") //not inline menu!
00665         showInline = false;
00666     else if( item == "IH") //inline  header!
00667         showInlineHeader= true;
00668     else if ( item == "NIH") //not inline  header!
00669         showInlineHeader = false;
00670     else if( item == "IA") //inline alias!
00671         showInlineAlias = true;
00672     else if (  item == "NIA") //not inline alias!
00673         showInlineAlias = false;
00674     else if( ( item ).contains( "IL" )) //inline limite!
00675     {
00676         QString tmp( item );
00677         tmp = tmp.remove( "IL[" );
00678         tmp = tmp.remove( ']' );
00679         bool ok;
00680         int _inlineValue = tmp.toInt(&ok);
00681         if ( !ok ) //error
00682             _inlineValue = -1;
00683         inlineValue =  _inlineValue;
00684     }
00685     else
00686         kDebug()<<" This attribute is not supported :"<<item;
00687 }
00688 
00689 void KServiceGroup::setLayoutInfo(const QStringList &layout)
00690 {
00691     Q_D(KServiceGroup);
00692     d->sortOrder = layout;
00693 }
00694 
00695 QStringList KServiceGroup::layoutInfo() const
00696 {
00697     Q_D(const KServiceGroup);
00698     return d->sortOrder;
00699 }
00700 
00701 KServiceGroup::Ptr
00702 KServiceGroup::baseGroup( const QString & _baseGroupName )
00703 {
00704     return KServiceGroupFactory::self()->findBaseGroup(_baseGroupName, true);
00705 }
00706 
00707 KServiceGroup::Ptr
00708 KServiceGroup::root()
00709 {
00710    return KServiceGroupFactory::self()->findGroupByDesktopPath("/", true);
00711 }
00712 
00713 KServiceGroup::Ptr
00714 KServiceGroup::group(const QString &relPath)
00715 {
00716    if (relPath.isEmpty()) return root();
00717    return KServiceGroupFactory::self()->findGroupByDesktopPath(relPath, true);
00718 }
00719 
00720 KServiceGroup::Ptr
00721 KServiceGroup::childGroup(const QString &parent)
00722 {
00723    return KServiceGroupFactory::self()->findGroupByDesktopPath("#parent#"+parent, true);
00724 }
00725 
00726 QString KServiceGroup::baseGroupName() const
00727 {
00728     return d_func()->m_strBaseGroupName;
00729 }
00730 
00731 QString
00732 KServiceGroup::directoryEntryPath() const
00733 {
00734     Q_D(const KServiceGroup);
00735    return d->directoryEntryPath;
00736 }
00737 
00738 class KServiceSeparatorPrivate : public KSycocaEntryPrivate
00739 {
00740     public:
00741         K_SYCOCATYPE( KST_KServiceSeparator, KSycocaEntryPrivate )
00742 
00743         KServiceSeparatorPrivate(const QString &name)
00744             : KSycocaEntryPrivate(name)
00745         {
00746         }
00747 
00748         virtual QString name() const
00749         {
00750             return QLatin1String("separator");
00751         }
00752 
00753 };
00754 
00755 KServiceSeparator::KServiceSeparator( )
00756     : KSycocaEntry(*new KServiceSeparatorPrivate("separator"))
00757 {
00758 }
00759 
00760 

KDECore

Skip menu "KDECore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • 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
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
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