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

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • services
kservicegroup.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  * Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License version 2 as published by the Free Software Foundation;
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public License
14  * along with this library; see the file COPYING.LIB. If not, write to
15  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  * Boston, MA 02110-1301, USA.
17  **/
18 
19 #include "kservicegroup.h"
20 #include "kservicegroup_p.h"
21 #include "kservicefactory.h"
22 #include "kservicegroupfactory.h"
23 #include "kservice.h"
24 #include <ksycoca.h>
25 #include <kglobal.h>
26 #include <kstandarddirs.h>
27 #include <klocale.h>
28 #include <kdebug.h>
29 #include <ksortablelist.h>
30 #include <kdesktopfile.h>
31 #include <kconfiggroup.h>
32 
33 
34 KServiceGroup::KServiceGroup( const QString & name )
35  : KSycocaEntry(*new KServiceGroupPrivate(name))
36 {
37 }
38 
39 KServiceGroup::KServiceGroup( const QString &configFile, const QString & _relpath )
40  : KSycocaEntry(*new KServiceGroupPrivate(_relpath))
41 {
42  Q_D(KServiceGroup);
43 
44  QString cfg = configFile;
45  if (cfg.isEmpty())
46  cfg = _relpath + QLatin1String(".directory");
47 
48  d->load(cfg);
49 }
50 
51 void KServiceGroupPrivate::load(const QString &cfg)
52 {
53  directoryEntryPath = cfg;
54 
55  const KDesktopFile desktopFile( cfg );
56 
57  const KConfigGroup config = desktopFile.desktopGroup();
58 
59  m_strCaption = config.readEntry( "Name" );
60  m_strIcon = config.readEntry( "Icon" );
61  m_strComment = config.readEntry( "Comment" );
62  deleted = config.readEntry("Hidden", false );
63  m_bNoDisplay = desktopFile.noDisplay();
64  m_strBaseGroupName = config.readEntry( "X-KDE-BaseGroup" );
65  suppressGenericNames = config.readEntry( "X-KDE-SuppressGenericNames", QStringList() );
66 // d->sortOrder = config.readEntry("SortOrder", QStringList());
67 
68  // Fill in defaults.
69  if (m_strCaption.isEmpty())
70  {
71  m_strCaption = path;
72  if (m_strCaption.endsWith(QLatin1Char('/')))
73  m_strCaption = m_strCaption.left(m_strCaption.length()-1);
74  int i = m_strCaption.lastIndexOf(QLatin1Char('/'));
75  if (i > 0)
76  m_strCaption = m_strCaption.mid(i+1);
77  }
78  if (m_strIcon.isEmpty())
79  m_strIcon = QString::fromLatin1("folder");
80 }
81 
82 KServiceGroup::KServiceGroup( QDataStream& _str, int offset, bool deep ) :
83  KSycocaEntry(*new KServiceGroupPrivate(_str, offset))
84 {
85  Q_D(KServiceGroup);
86  d->m_bDeep = deep;
87  d->load( _str );
88 }
89 
90 KServiceGroup::~KServiceGroup()
91 {
92 }
93 
94 QString KServiceGroup::relPath() const
95 {
96  return entryPath();
97 }
98 
99 QString KServiceGroup::caption() const
100 {
101  Q_D(const KServiceGroup);
102  return d->m_strCaption;
103 }
104 
105 QString KServiceGroup::icon() const
106 {
107  Q_D(const KServiceGroup);
108  return d->m_strIcon;
109 }
110 
111 QString KServiceGroup::comment() const
112 {
113  Q_D(const KServiceGroup);
114  return d->m_strComment;
115 }
116 
117 int KServiceGroup::childCount() const
118 {
119  Q_D(const KServiceGroup);
120  return d->childCount();
121 }
122 
123 int KServiceGroupPrivate::childCount() const
124 {
125  if (m_childCount == -1)
126  {
127  m_childCount = 0;
128 
129  for( KServiceGroup::List::ConstIterator it = m_serviceList.begin();
130  it != m_serviceList.end(); ++it)
131  {
132  KSycocaEntry::Ptr p = *it;
133  if (p->isType(KST_KService))
134  {
135  KService::Ptr service = KService::Ptr::staticCast( p );
136  if (!service->noDisplay())
137  m_childCount++;
138  }
139  else if (p->isType(KST_KServiceGroup))
140  {
141  KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( p );
142  m_childCount += serviceGroup->childCount();
143  }
144  }
145  }
146  return m_childCount;
147 }
148 
149 
150 bool KServiceGroup::showInlineHeader() const
151 {
152  Q_D(const KServiceGroup);
153  return d->m_bShowInlineHeader;
154 }
155 
156 bool KServiceGroup::showEmptyMenu() const
157 {
158  Q_D(const KServiceGroup);
159  return d->m_bShowEmptyMenu;
160 }
161 
162 bool KServiceGroup::inlineAlias() const
163 {
164  Q_D(const KServiceGroup);
165  return d->m_bInlineAlias;
166 }
167 
168 void KServiceGroup::setInlineAlias(bool _b)
169 {
170  Q_D(KServiceGroup);
171  d->m_bInlineAlias = _b;
172 }
173 
174 void KServiceGroup::setShowEmptyMenu(bool _b)
175 {
176  Q_D(KServiceGroup);
177  d->m_bShowEmptyMenu=_b;
178 }
179 
180 void KServiceGroup::setShowInlineHeader(bool _b)
181 {
182  Q_D(KServiceGroup);
183  d->m_bShowInlineHeader=_b;
184 }
185 
186 int KServiceGroup::inlineValue() const
187 {
188  Q_D(const KServiceGroup);
189  return d->m_inlineValue;
190 }
191 
192 void KServiceGroup::setInlineValue(int _val)
193 {
194  Q_D(KServiceGroup);
195  d->m_inlineValue = _val;
196 }
197 
198 bool KServiceGroup::allowInline() const
199 {
200  Q_D(const KServiceGroup);
201  return d->m_bAllowInline;
202 }
203 
204 void KServiceGroup::setAllowInline(bool _b)
205 {
206  Q_D(KServiceGroup);
207  d->m_bAllowInline = _b;
208 }
209 
210 bool KServiceGroup::noDisplay() const
211 {
212  Q_D(const KServiceGroup);
213  return d->m_bNoDisplay || d->m_strCaption.startsWith(QLatin1Char('.'));
214 }
215 
216 QStringList KServiceGroup::suppressGenericNames() const
217 {
218  Q_D(const KServiceGroup);
219  return d->suppressGenericNames;
220 }
221 
222 void KServiceGroupPrivate::load( QDataStream& s )
223 {
224  QStringList groupList;
225  qint8 noDisplay;
226  qint8 _showEmptyMenu;
227  qint8 inlineHeader;
228  qint8 _inlineAlias;
229  qint8 _allowInline;
230  s >> m_strCaption >> m_strIcon >>
231  m_strComment >> groupList >> m_strBaseGroupName >> m_childCount >>
232  noDisplay >> suppressGenericNames >> directoryEntryPath >>
233  sortOrder >> _showEmptyMenu >> inlineHeader >> _inlineAlias >> _allowInline;
234 
235  m_bNoDisplay = (noDisplay != 0);
236  m_bShowEmptyMenu = ( _showEmptyMenu != 0 );
237  m_bShowInlineHeader = ( inlineHeader != 0 );
238  m_bInlineAlias = ( _inlineAlias != 0 );
239  m_bAllowInline = ( _allowInline != 0 );
240 
241  if (m_bDeep)
242  {
243  Q_FOREACH(const QString &path, groupList)
244  {
245  if ( path.endsWith( QLatin1Char( '/' ) ) )
246  {
247  KServiceGroup::Ptr serviceGroup;
248  serviceGroup = KServiceGroupFactory::self()->findGroupByDesktopPath(path, false);
249  if (serviceGroup)
250  m_serviceList.append( KServiceGroup::SPtr::staticCast(serviceGroup) );
251  }
252  else
253  {
254  KService::Ptr service;
255  service = KServiceFactory::self()->findServiceByDesktopPath(path);
256  if (service)
257  m_serviceList.append( KServiceGroup::SPtr::staticCast(service) );
258  }
259  }
260  }
261 }
262 
263 void KServiceGroup::addEntry( const KSycocaEntry::Ptr& entry)
264 {
265  Q_D(KServiceGroup);
266  d->m_serviceList.append(entry);
267 }
268 
269 void KServiceGroupPrivate::save( QDataStream& s )
270 {
271  KSycocaEntryPrivate::save( s );
272 
273  QStringList groupList;
274  Q_FOREACH(KSycocaEntry::Ptr p, m_serviceList)
275  {
276  if (p->isType(KST_KService))
277  {
278  KService::Ptr service = KService::Ptr::staticCast( p );
279  groupList.append( service->entryPath() );
280  }
281  else if (p->isType(KST_KServiceGroup))
282  {
283  KServiceGroup::Ptr serviceGroup = KServiceGroup::Ptr::staticCast( p );
284  groupList.append( serviceGroup->relPath() );
285  }
286  else
287  {
288  //fprintf(stderr, "KServiceGroup: Unexpected object in list!\n");
289  }
290  }
291 
292  (void) childCount();
293 
294  qint8 noDisplay = m_bNoDisplay ? 1 : 0;
295  qint8 _showEmptyMenu = m_bShowEmptyMenu ? 1 : 0;
296  qint8 inlineHeader = m_bShowInlineHeader ? 1 : 0;
297  qint8 _inlineAlias = m_bInlineAlias ? 1 : 0;
298  qint8 _allowInline = m_bAllowInline ? 1 : 0;
299  s << m_strCaption << m_strIcon <<
300  m_strComment << groupList << m_strBaseGroupName << m_childCount <<
301  noDisplay << suppressGenericNames << directoryEntryPath <<
302  sortOrder <<_showEmptyMenu <<inlineHeader<<_inlineAlias<<_allowInline;
303 }
304 
305 QList<KServiceGroup::Ptr> KServiceGroup::groupEntries(EntriesOptions options)
306 {
307  Q_D(KServiceGroup);
308  bool sort = options & SortEntries || options & AllowSeparators;
309  QList<KServiceGroup::Ptr> list;
310  List tmp = d->entries(this, sort, options & ExcludeNoDisplay, options & AllowSeparators, options & SortByGenericName);
311  foreach(const SPtr &ptr, tmp) {
312  if (ptr->isType(KST_KServiceGroup))
313  list.append(Ptr::staticCast(ptr));
314  else if (ptr->isType(KST_KServiceSeparator))
315  list.append(KServiceGroup::Ptr(static_cast<KServiceGroup *>(new KSycocaEntry())));
316  else if (sort && ptr->isType(KST_KService))
317  break;
318  }
319  return list;
320 }
321 
322 KService::List KServiceGroup::serviceEntries(EntriesOptions options)
323 {
324  Q_D(KServiceGroup);
325  bool sort = options & SortEntries || options & AllowSeparators;
326  QList<KService::Ptr> list;
327  List tmp = d->entries(this, sort, options & ExcludeNoDisplay, options & AllowSeparators, options & SortByGenericName);
328  bool foundService = false;
329  foreach(const SPtr &ptr, tmp) {
330  if (ptr->isType(KST_KService)) {
331  list.append(KService::Ptr::staticCast(ptr));
332  foundService = true;
333  }
334  else if (ptr->isType(KST_KServiceSeparator) && foundService) {
335  list.append(KService::Ptr(static_cast<KService *>(new KSycocaEntry())));
336  }
337  }
338  return list;
339 }
340 
341 KServiceGroup::List
342 KServiceGroup::entries(bool sort)
343 {
344  Q_D(KServiceGroup);
345  return d->entries(this, sort, true, false, false);
346 }
347 
348 KServiceGroup::List
349 KServiceGroup::entries(bool sort, bool excludeNoDisplay)
350 {
351  Q_D(KServiceGroup);
352  return d->entries(this, sort, excludeNoDisplay, false, false);
353 }
354 
355 KServiceGroup::List
356 KServiceGroup::entries(bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
357 {
358  Q_D(KServiceGroup);
359  return d->entries(this, sort, excludeNoDisplay, allowSeparators, sortByGenericName);
360 }
361 
362 static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator)
363 {
364  if (addSeparator && !sorted.isEmpty())
365  sorted.append(KSycocaEntry::Ptr(new KServiceSeparator()));
366  sorted.append(p);
367  addSeparator = false;
368 }
369 
370 KServiceGroup::List
371 KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
372 {
373  KServiceGroup::Ptr grp;
374 
375  // If the entries haven't been loaded yet, we have to reload ourselves
376  // together with the entries. We can't only load the entries afterwards
377  // since the offsets could have been changed if the database has changed.
378 
379  if (!m_bDeep) {
380 
381  grp = KServiceGroupFactory::self()->findGroupByDesktopPath(path, true);
382 
383  group = grp.data();
384  if (0 == group) // No guarantee that we still exist!
385  return KServiceGroup::List();
386  }
387 
388  if (!sort)
389  return group->d_func()->m_serviceList;
390 
391  // Sort the list alphabetically, according to locale.
392  // Groups come first, then services.
393 
394  KSortableList<KServiceGroup::SPtr,QByteArray> slist;
395  KSortableList<KServiceGroup::SPtr,QByteArray> glist;
396  Q_FOREACH (KSycocaEntry::Ptr p, group->d_func()->m_serviceList)
397  {
398  bool noDisplay = p->isType(KST_KServiceGroup) ?
399  static_cast<KServiceGroup *>(p.data())->noDisplay() :
400  static_cast<KService *>(p.data())->noDisplay();
401  if (excludeNoDisplay && noDisplay)
402  continue;
403  // Choose the right list
404  KSortableList<KServiceGroup::SPtr,QByteArray> & list = p->isType(KST_KServiceGroup) ? glist : slist;
405  QString name;
406  if (p->isType(KST_KServiceGroup))
407  name = static_cast<KServiceGroup *>(p.data())->caption();
408  else if (sortByGenericName)
409  name = static_cast<KService *>(p.data())->genericName() + QLatin1Char(' ') + p->name();
410  else
411  name = p->name() + QLatin1Char(' ') + static_cast<KService *>(p.data())->genericName();
412 
413  const QByteArray nameStr = name.toLocal8Bit();
414 
415  QByteArray key;
416  // strxfrm() crashes on Solaris and strxfrm is not defined under wince
417 #if !defined(USE_SOLARIS) && !defined(_WIN32_WCE)
418  // maybe it'd be better to use wcsxfrm() where available
419  key.resize( name.length() * 4 + 1 );
420  size_t ln = strxfrm(key.data(), nameStr.constData(), key.size());
421  if( ln != size_t( -1 ))
422  {
423  key.resize(ln);
424  if( (int)ln >= key.size())
425  { // didn't fit?
426  ln = strxfrm( key.data(), nameStr.constData(), key.size());
427  if( ln == size_t( -1 ))
428  key = nameStr;
429  }
430  }
431  else
432 #endif
433  {
434  key = nameStr;
435  }
436  list.insert(key,KServiceGroup::SPtr(p));
437  }
438  // Now sort
439  slist.sort();
440  glist.sort();
441 
442  if (sortOrder.isEmpty())
443  {
444  sortOrder << QString::fromLatin1(":M");
445  sortOrder << QString::fromLatin1(":F");
446  sortOrder << QString::fromLatin1(":OIH IL[4]"); //just inline header
447  }
448 
449  QString rp = path;
450  if(rp == QLatin1String("/")) rp.clear();
451 
452  // Iterate through the sort spec list.
453  // If an entry gets mentioned explicitly, we remove it from the sorted list
454  Q_FOREACH (const QString &item, sortOrder)
455  {
456  if (item.isEmpty()) continue;
457  if (item[0] == QLatin1Char('/'))
458  {
459  QString groupPath = rp + item.mid(1) + QLatin1Char('/');
460  // Remove entry from sorted list of services.
461  for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = glist.begin(); it2 != glist.end(); ++it2)
462  {
463  const KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( (*it2).value() );
464  if (group->relPath() == groupPath)
465  {
466  glist.erase(it2);
467  break;
468  }
469  }
470  }
471  else if (item[0] != QLatin1Char(':'))
472  {
473  // Remove entry from sorted list of services.
474  // TODO: Remove item from sortOrder-list if not found
475  // TODO: This prevents duplicates
476  for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = slist.begin(); it2 != slist.end(); ++it2)
477  {
478  const KService::Ptr service = KService::Ptr::staticCast( (*it2).value() );
479  if (service->menuId() == item)
480  {
481  slist.erase(it2);
482  break;
483  }
484  }
485  }
486  }
487 
488  KServiceGroup::List sorted;
489 
490  bool needSeparator = false;
491  // Iterate through the sort spec list.
492  // Add the entries to the list according to the sort spec.
493  for (QStringList::ConstIterator it(sortOrder.constBegin()); it != sortOrder.constEnd(); ++it)
494  {
495  const QString &item = *it;
496  if (item.isEmpty()) continue;
497  if (item[0] == QLatin1Char(':'))
498  {
499  // Special condition...
500  if (item == QLatin1String(":S"))
501  {
502  if (allowSeparators)
503  needSeparator = true;
504  }
505  else if ( item.contains( QLatin1String(":O") ) )
506  {
507  //todo parse attribute:
508  QString tmp( item );
509  tmp = tmp.remove(QLatin1String(":O"));
510  QStringList optionAttribute = tmp.split(QLatin1Char(' '), QString::SkipEmptyParts);
511  if ( optionAttribute.isEmpty() )
512  optionAttribute.append( tmp );
513  bool showEmptyMenu = false;
514  bool showInline = false;
515  bool showInlineHeader = false;
516  bool showInlineAlias = false;
517  int inlineValue = -1;
518 
519  for ( QStringList::Iterator it3 = optionAttribute.begin(); it3 != optionAttribute.end(); ++it3 )
520  {
521  parseAttribute( *it3, showEmptyMenu, showInline, showInlineHeader, showInlineAlias, inlineValue );
522  }
523  for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = glist.begin(); it2 != glist.end(); ++it2)
524  {
525  KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( (*it2).value() );
526  group->setShowEmptyMenu( showEmptyMenu );
527  group->setAllowInline( showInline );
528  group->setShowInlineHeader( showInlineHeader );
529  group->setInlineAlias( showInlineAlias );
530  group->setInlineValue( inlineValue );
531  }
532 
533  }
534  else if (item == QLatin1String(":M"))
535  {
536  // Add sorted list of sub-menus
537  for(KSortableList<KServiceGroup::SPtr,QByteArray>::const_iterator it2 = glist.constBegin(); it2 != glist.constEnd(); ++it2)
538  {
539  addItem(sorted, (*it2).value(), needSeparator);
540  }
541  }
542  else if (item == QLatin1String(":F"))
543  {
544  // Add sorted list of services
545  for(KSortableList<KServiceGroup::SPtr,QByteArray>::const_iterator it2 = slist.constBegin(); it2 != slist.constEnd(); ++it2)
546  {
547  addItem(sorted, (*it2).value(), needSeparator);
548  }
549  }
550  else if (item == QLatin1String(":A"))
551  {
552  // Add sorted lists of services and submenus
553  KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it_s = slist.begin();
554  KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it_g = glist.begin();
555 
556  while(true)
557  {
558  if (it_s == slist.end())
559  {
560  if (it_g == glist.end())
561  break; // Done
562 
563  // Insert remaining sub-menu
564  addItem(sorted, (*it_g).value(), needSeparator);
565  it_g++;
566  }
567  else if (it_g == glist.end())
568  {
569  // Insert remaining service
570  addItem(sorted, (*it_s).value(), needSeparator);
571  it_s++;
572  }
573  else if ((*it_g).key() < (*it_s).key())
574  {
575  // Insert sub-menu first
576  addItem(sorted, (*it_g).value(), needSeparator);
577  it_g++;
578  }
579  else
580  {
581  // Insert service first
582  addItem(sorted, (*it_s).value(), needSeparator);
583  it_s++;
584  }
585  }
586  }
587  }
588  else if (item[0] == QLatin1Char('/'))
589  {
590  QString groupPath = rp + item.mid(1) + QLatin1Char('/');
591 
592  for (KServiceGroup::List::ConstIterator it2(group->d_func()->m_serviceList.constBegin());
593  it2 != group->d_func()->m_serviceList.constEnd(); ++it2)
594  {
595  if (!(*it2)->isType(KST_KServiceGroup))
596  continue;
597  KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast( *it2 );
598  if (group->relPath() == groupPath)
599  {
600  if (!excludeNoDisplay || !group->noDisplay())
601  {
602  ++it;
603  const QString &nextItem =
604  (it == sortOrder.constEnd()) ? QString() : *it;
605 
606  if ( nextItem.startsWith( QLatin1String(":O") ) )
607  {
608  QString tmp( nextItem );
609  tmp = tmp.remove(QLatin1String(":O"));
610  QStringList optionAttribute = tmp.split(QLatin1Char(' '), QString::SkipEmptyParts);
611  if ( optionAttribute.isEmpty() )
612  optionAttribute.append( tmp );
613  bool bShowEmptyMenu = false;
614  bool bShowInline = false;
615  bool bShowInlineHeader = false;
616  bool bShowInlineAlias = false;
617  int inlineValue = -1;
618  Q_FOREACH( const QString &opt_attr, optionAttribute )
619  {
620  parseAttribute( opt_attr, bShowEmptyMenu, bShowInline, bShowInlineHeader, bShowInlineAlias , inlineValue );
621  group->setShowEmptyMenu( bShowEmptyMenu );
622  group->setAllowInline( bShowInline );
623  group->setShowInlineHeader( bShowInlineHeader );
624  group->setInlineAlias( bShowInlineAlias );
625  group->setInlineValue( inlineValue );
626  }
627  }
628  else
629  it--;
630 
631  addItem(sorted, KServiceGroup::SPtr::staticCast(group), needSeparator);
632  }
633  break;
634  }
635  }
636  }
637  else
638  {
639  for (KServiceGroup::List::ConstIterator it2(group->d_func()->m_serviceList.constBegin());
640  it2 != group->d_func()->m_serviceList.constEnd(); ++it2)
641  {
642  if (!(*it2)->isType(KST_KService))
643  continue;
644  const KService::Ptr service = KService::Ptr::staticCast( *it2 );
645  if (service->menuId() == item)
646  {
647  if (!excludeNoDisplay || !service->noDisplay())
648  addItem(sorted, (*it2), needSeparator);
649  break;
650  }
651  }
652  }
653  }
654 
655  return sorted;
656 }
657 
658 void KServiceGroupPrivate::parseAttribute( const QString &item , bool &showEmptyMenu, bool &showInline, bool &showInlineHeader, bool & showInlineAlias , int &inlineValue )
659 {
660  if( item == QLatin1String("ME")) //menu empty
661  showEmptyMenu=true;
662  else if ( item == QLatin1String("NME")) //not menu empty
663  showEmptyMenu=false;
664  else if( item == QLatin1String("I")) //inline menu !
665  showInline = true;
666  else if ( item == QLatin1String("NI")) //not inline menu!
667  showInline = false;
668  else if( item == QLatin1String("IH")) //inline header!
669  showInlineHeader= true;
670  else if ( item == QLatin1String("NIH")) //not inline header!
671  showInlineHeader = false;
672  else if( item == QLatin1String("IA")) //inline alias!
673  showInlineAlias = true;
674  else if ( item == QLatin1String("NIA")) //not inline alias!
675  showInlineAlias = false;
676  else if( ( item ).contains( QLatin1String("IL") )) //inline limite!
677  {
678  QString tmp( item );
679  tmp = tmp.remove( QLatin1String("IL[") );
680  tmp = tmp.remove( QLatin1Char(']') );
681  bool ok;
682  int _inlineValue = tmp.toInt(&ok);
683  if ( !ok ) //error
684  _inlineValue = -1;
685  inlineValue = _inlineValue;
686  }
687  else
688  kDebug()<<" This attribute is not supported :"<<item;
689 }
690 
691 void KServiceGroup::setLayoutInfo(const QStringList &layout)
692 {
693  Q_D(KServiceGroup);
694  d->sortOrder = layout;
695 }
696 
697 QStringList KServiceGroup::layoutInfo() const
698 {
699  Q_D(const KServiceGroup);
700  return d->sortOrder;
701 }
702 
703 #ifndef KDE_NO_DEPRECATED
704 KServiceGroup::Ptr
705 KServiceGroup::baseGroup( const QString & _baseGroupName )
706 {
707  return KServiceGroupFactory::self()->findBaseGroup(_baseGroupName, true);
708 }
709 #endif
710 
711 KServiceGroup::Ptr
712 KServiceGroup::root()
713 {
714  return KServiceGroupFactory::self()->findGroupByDesktopPath(QString::fromLatin1("/"), true);
715 }
716 
717 KServiceGroup::Ptr
718 KServiceGroup::group(const QString &relPath)
719 {
720  if (relPath.isEmpty()) return root();
721  return KServiceGroupFactory::self()->findGroupByDesktopPath(relPath, true);
722 }
723 
724 KServiceGroup::Ptr
725 KServiceGroup::childGroup(const QString &parent)
726 {
727  return KServiceGroupFactory::self()->findGroupByDesktopPath(QString::fromLatin1("#parent#")+parent, true);
728 }
729 
730 QString KServiceGroup::baseGroupName() const
731 {
732  return d_func()->m_strBaseGroupName;
733 }
734 
735 QString
736 KServiceGroup::directoryEntryPath() const
737 {
738  Q_D(const KServiceGroup);
739  return d->directoryEntryPath;
740 }
741 
742 class KServiceSeparatorPrivate : public KSycocaEntryPrivate
743 {
744  public:
745  K_SYCOCATYPE( KST_KServiceSeparator, KSycocaEntryPrivate )
746 
747  KServiceSeparatorPrivate(const QString &name)
748  : KSycocaEntryPrivate(name)
749  {
750  }
751 
752  virtual QString name() const
753  {
754  return QLatin1String("separator");
755  }
756 
757 };
758 
759 KServiceSeparator::KServiceSeparator( )
760  : KSycocaEntry(*new KServiceSeparatorPrivate(QString::fromLatin1("separator")))
761 {
762 }
763 
764 
KServiceFactory::findServiceByDesktopPath
virtual KService::Ptr findServiceByDesktopPath(const QString &_name)
Find a service ( by desktop path, e.g.
Definition: kservicefactory.cpp:127
KGlobal::caption
QString caption()
Returns a text for the window caption.
Definition: kglobal.cpp:292
KServiceGroupFactory::findBaseGroup
KServiceGroup::Ptr findBaseGroup(const QString &_baseGroupName, bool deep=true)
Find a base group by name, e.g.
Definition: kservicegroupfactory.cpp:82
kservicegroup.h
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: kconfiggroup.h:38
KServiceGroup::noDisplay
bool noDisplay() const
Returns true if the NoDisplay flag was set, i.e.
Definition: kservicegroup.cpp:210
KServiceGroup::directoryEntryPath
QString directoryEntryPath() const
Returns a path to the .directory file describing this service group.
Definition: kservicegroup.cpp:736
KServiceGroup
KServiceGroup represents a group of service, for example screensavers.
Definition: kservicegroup.h:62
KService::noDisplay
bool noDisplay() const
Whether the entry should be suppressed in the K menu.
Definition: kservice.cpp:704
KServiceGroupPrivate::m_strCaption
QString m_strCaption
Definition: kservicegroup_p.h:76
kdebug.h
KServiceGroupPrivate
Definition: kservicegroup_p.h:27
KSharedPtr::data
T * data()
Definition: ksharedptr.h:111
ksortablelist.h
QByteArray
KMacroExpander::group
Definition: kmacroexpander_unix.cpp:34
KServiceGroupPrivate::m_bAllowInline
bool m_bAllowInline
Definition: kservicegroup_p.h:71
kservicegroupfactory.h
KServiceGroup::showInlineHeader
bool showInlineHeader() const
Definition: kservicegroup.cpp:150
QDataStream
KServiceGroup::relPath
QString relPath() const
Returns the relative path of the service group.
Definition: kservicegroup.cpp:94
KServiceGroupPrivate::childCount
int childCount() const
Definition: kservicegroup.cpp:123
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
KServiceGroup::KServiceGroup
KServiceGroup(const QString &name)
Construct a dummy servicegroup indexed with name.
Definition: kservicegroup.cpp:34
KService
Represent a service, like an application or plugin bound to one or several mimetypes (or servicetypes...
Definition: kservice.h:58
KServiceGroup::allowInline
bool allowInline() const
Definition: kservicegroup.cpp:198
KServiceGroup::icon
QString icon() const
Returns the name of the icon associated with the group.
Definition: kservicegroup.cpp:105
KServiceGroup::serviceEntries
KService::List serviceEntries(EntriesOptions options=ExcludeNoDisplay)
entries of this service group
Definition: kservicegroup.cpp:322
KServiceGroup::~KServiceGroup
virtual ~KServiceGroup()
Definition: kservicegroup.cpp:90
KSortableList::insert
void insert(Key i, const T &t)
Insert a KSortableItem with the given values.
Definition: ksortablelist.h:152
KSortableList::sort
void sort()
Sorts the KSortableItems.
Definition: ksortablelist.h:176
QList< KSortableItem< T, Key > >::erase
iterator erase(iterator pos)
KServiceGroupPrivate::m_childCount
int m_childCount
Definition: kservicegroup_p.h:83
KServiceGroup::caption
QString caption() const
Returns the caption of this group.
Definition: kservicegroup.cpp:99
KServiceGroupPrivate::parseAttribute
void parseAttribute(const QString &item, bool &showEmptyMenu, bool &showInline, bool &showInlineHeader, bool &showInlineAlias, int &inlineValue)
This function parse attributes into menu.
Definition: kservicegroup.cpp:658
KServiceGroup::setShowEmptyMenu
void setShowEmptyMenu(bool b)
Definition: kservicegroup.cpp:174
KServiceGroup::groupEntries
QList< Ptr > groupEntries(EntriesOptions options=ExcludeNoDisplay)
subgroups for this service group
Definition: kservicegroup.cpp:305
QString::remove
QString & remove(int position, int n)
kdesktopfile.h
klocale.h
KServiceGroupPrivate::sortOrder
QStringList sortOrder
Definition: kservicegroup_p.h:75
KServiceGroup::ExcludeNoDisplay
Definition: kservicegroup.h:209
KServiceGroup::setInlineAlias
void setInlineAlias(bool _b)
Definition: kservicegroup.cpp:168
KSycocaEntryPrivate::path
QString path
Definition: ksycocaentry_p.h:77
KDesktopFile::noDisplay
bool noDisplay() const
Whether the entry should be suppressed in menus.
Definition: kdesktopfile.cpp:391
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:139
QString::lastIndexOf
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QList::value
T value(int i) const
QString::clear
void clear()
KST_KService
Definition: ksycocatype.h:31
KServiceGroupPrivate::m_strComment
QString m_strComment
Definition: kservicegroup_p.h:78
QByteArray::resize
void resize(int size)
kservicefactory.h
KServiceGroup::baseGroupName
QString baseGroupName() const
Returns a non-empty string if the group is a special base group.
Definition: kservicegroup.cpp:730
KSycocaEntryPrivate::save
virtual void save(QDataStream &s)
Definition: ksycocaentry.cpp:139
KServiceGroup::SortByGenericName
Definition: kservicegroup.h:211
KServiceGroupPrivate::entries
KServiceGroup::List entries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
Definition: kservicegroup.cpp:371
kglobal.h
KServiceSeparator
Definition: kservicegroup_p.h:86
QList::append
void append(const T &value)
KServiceGroupPrivate::name
virtual QString name() const
Definition: kservicegroup_p.h:49
KSycocaEntry::entryPath
QString entryPath() const
Definition: ksycocaentry.cpp:104
KServiceGroup::addEntry
void addEntry(const KSycocaEntry::Ptr &entry)
Definition: kservicegroup.cpp:263
KServiceGroupFactory::self
static KServiceGroupFactory * self()
Definition: kservicegroupfactory.cpp:60
KServiceGroupPrivate::m_bNoDisplay
bool m_bNoDisplay
Definition: kservicegroup_p.h:67
KServiceGroup::childCount
int childCount() const
Returns the total number of displayable services in this group and any of its subgroups.
Definition: kservicegroup.cpp:117
KSycocaEntry
Base class for all Sycoca entries.
Definition: ksycocaentry.h:41
QString::toInt
int toInt(bool *ok, int base) const
QList::isEmpty
bool isEmpty() const
KServiceGroupPrivate::m_bDeep
bool m_bDeep
Definition: kservicegroup_p.h:81
KServiceGroup::setInlineValue
void setInlineValue(int _val)
Definition: kservicegroup.cpp:192
QString::isEmpty
bool isEmpty() const
K_SYCOCATYPE
#define K_SYCOCATYPE(type, baseclass)
Definition: ksycocaentry_p.h:24
KServiceGroup::entries
List entries(bool sorted, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName=false)
List of all Services and ServiceGroups within this ServiceGroup.
Definition: kservicegroup.cpp:356
KServiceGroupPrivate::directoryEntryPath
QString directoryEntryPath
Definition: kservicegroup_p.h:74
QByteArray::constData
const char * constData() const
KService::menuId
QString menuId() const
Returns the menu ID of the service desktop entry.
Definition: kservice.cpp:771
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KServiceGroup::inlineAlias
bool inlineAlias() const
Definition: kservicegroup.cpp:162
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
KServiceGroupPrivate::m_bInlineAlias
bool m_bInlineAlias
Definition: kservicegroup_p.h:70
QList::Iterator
typedef Iterator
kservicegroup_p.h
KServiceGroup::inlineValue
int inlineValue() const
Definition: kservicegroup.cpp:186
KServiceGroup::SortEntries
Definition: kservicegroup.h:208
QString
QList
Definition: kaboutdata.h:33
KServiceGroupPrivate::m_strIcon
QString m_strIcon
Definition: kservicegroup_p.h:77
QStringList
kservice.h
KServiceGroupPrivate::save
virtual void save(QDataStream &s)
Definition: kservicegroup.cpp:269
KSycocaEntry::KSycocaEntry
KSycocaEntry()
Definition: ksycocaentry.cpp:31
QList::end
iterator end()
QString::toLocal8Bit
QByteArray toLocal8Bit() const
KSycocaEntryPrivate::deleted
bool deleted
Definition: ksycocaentry_p.h:76
addItem
static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator)
Definition: kservicegroup.cpp:362
KServiceGroup::setLayoutInfo
void setLayoutInfo(const QStringList &layout)
Definition: kservicegroup.cpp:691
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
KST_KServiceSeparator
Definition: ksycocatype.h:34
QLatin1Char
KDesktopFile
KDE Desktop File Management.
Definition: kdesktopfile.h:38
ksycoca.h
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:53
KSortableList
KSortableList is a QList which associates a key with each item in the list.
Definition: ksortablelist.h:144
KServiceGroupPrivate::m_strBaseGroupName
QString m_strBaseGroupName
Definition: kservicegroup_p.h:82
KServiceGroup::childGroup
static Ptr childGroup(const QString &parent)
Returns the group of services that have X-KDE-ParentApp equal to parent (siblings).
Definition: kservicegroup.cpp:725
KServiceGroup::List
QList< SPtr > List
Definition: kservicegroup.h:68
QString::mid
QString mid(int position, int n) const
KServiceGroup::suppressGenericNames
QStringList suppressGenericNames() const
Returns a list of untranslated generic names that should be be suppressed when showing this group...
Definition: kservicegroup.cpp:216
QLatin1String
KServiceGroupPrivate::m_bShowInlineHeader
bool m_bShowInlineHeader
Definition: kservicegroup_p.h:69
KServiceGroup::layoutInfo
QStringList layoutInfo() const
Definition: kservicegroup.cpp:697
kstandarddirs.h
KSharedPtr< KService >::staticCast
static KSharedPtr< KService > staticCast(const KSharedPtr< U > &o)
Convert KSharedPtr to KSharedPtr, using a static_cast.
Definition: ksharedptr.h:173
KServiceGroup::baseGroup
static Ptr baseGroup(const QString &baseGroupName)
Returns the group for the given baseGroupName.
Definition: kservicegroup.cpp:705
KServiceGroup::showEmptyMenu
bool showEmptyMenu() const
Return true if we want to display empty menu entry.
Definition: kservicegroup.cpp:156
KServiceGroup::root
static Ptr root()
Returns the root service group.
Definition: kservicegroup.cpp:712
QList::ConstIterator
typedef ConstIterator
QString::length
int length() const
KSycocaEntryPrivate
Definition: ksycocaentry_p.h:29
QByteArray::data
char * data()
KServiceGroupPrivate::m_bShowEmptyMenu
bool m_bShowEmptyMenu
Definition: kservicegroup_p.h:68
QString::left
QString left(int n) const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
kDebug
#define kDebug
Definition: kdebug.h:316
KServiceSeparator::KServiceSeparator
KServiceSeparator()
Construct a service separator.
Definition: kservicegroup.cpp:759
KServiceGroupPrivate::suppressGenericNames
QStringList suppressGenericNames
Definition: kservicegroup_p.h:73
KServiceGroup::comment
QString comment() const
Returns the comment about this service group.
Definition: kservicegroup.cpp:111
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
KST_KServiceGroup
Definition: ksycocatype.h:33
KServiceGroup::group
static Ptr group(const QString &relPath)
Returns the group with the given relative path.
Definition: kservicegroup.cpp:718
QByteArray::size
int size() const
KServiceGroupPrivate::load
void load(const QString &cfg)
Definition: kservicegroup.cpp:51
KServiceFactory::self
static KServiceFactory * self()
Definition: kservicefactory.cpp:81
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KDesktopFile::desktopGroup
KConfigGroup desktopGroup() const
Definition: kdesktopfile.cpp:73
QList::begin
iterator begin()
KServiceGroupPrivate::m_serviceList
KServiceGroup::List m_serviceList
Definition: kservicegroup_p.h:80
kconfiggroup.h
KServiceGroup::setAllowInline
void setAllowInline(bool _b)
Definition: kservicegroup.cpp:204
KServiceGroup::AllowSeparators
Definition: kservicegroup.h:210
KSycocaEntryPrivate::name
virtual QString name() const =0
KServiceGroup::setShowInlineHeader
void setShowInlineHeader(bool _b)
Definition: kservicegroup.cpp:180
KServiceGroupFactory::findGroupByDesktopPath
virtual KServiceGroup::Ptr findGroupByDesktopPath(const QString &_name, bool deep=true)
Find a group ( by desktop path, e.g.
Definition: kservicegroupfactory.cpp:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal