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

KDECore

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

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
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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