home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kservicegroup.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.2 KB  |  341 lines

  1. /* This file is part of the KDE project
  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. #ifndef __kservicegroup_h__
  20. #define __kservicegroup_h__
  21.  
  22. #include <qptrlist.h>
  23. #include <qstring.h>
  24. #include <qshared.h>
  25. #include <qdatastream.h>
  26. #include <qvariant.h>
  27.  
  28. #include <kdesktopfile.h>
  29.  
  30. #include "ksycocaentry.h"
  31. #include "ksycocatype.h"
  32. #include "kservice.h"
  33.  
  34. class KBuildServiceGroupFactory;
  35.  
  36. /**
  37.  * KServiceGroup represents a group of service, for example
  38.  * screensavers.
  39.  * This class is typically used like this:
  40.  *
  41.  * \code
  42.  * // Lookup screensaver group
  43.  * KServiceGroup::Ptr group = KServiceGroup::baseGroup("screensavers");
  44.  * if (!group || !group->isValid()) return;
  45.  *
  46.  * KServiceGroup::List list = group->entries();
  47.  *
  48.  * // Iterate over all entries in the group
  49.  * for( KServiceGroup::List::ConstIterator it = list.begin();
  50.  *      it != list.end(); it++)
  51.  * {
  52.  *    KSycocaEntry *p = (*it);
  53.  *    if (p->isType(KST_KService))
  54.  *    {
  55.  *       KService *s = static_cast<KService *>(p);
  56.  *       printf("Name = %s\n", s->name().latin1());
  57.  *    }
  58.  *    else if (p->isType(KST_KServiceGroup))
  59.  *    {
  60.  *       KServiceGroup *g = static_cast<KServiceGroup *>(p);
  61.  *       // Sub group ...
  62.  *    }
  63.  * }
  64.  * \endcode
  65.  * @short Represents a group of services
  66.  */
  67. class KIO_EXPORT KServiceGroup : public KSycocaEntry
  68. {
  69.   friend class KBuildServiceGroupFactory;
  70.   K_SYCOCATYPE( KST_KServiceGroup, KSycocaEntry )
  71.  
  72. public:
  73.   typedef KSharedPtr<KServiceGroup> Ptr;
  74.   typedef KSharedPtr<KSycocaEntry> SPtr;
  75.   typedef QValueList<SPtr> List;
  76. public:
  77.   /**
  78.    * Construct a dummy servicegroup indexed with @p name.
  79.    * @param name the name of the service group
  80.    * @since 3.1
  81.    */
  82.   KServiceGroup( const QString & name );
  83.  
  84.   /**
  85.    * Construct a service and take all informations from a config file
  86.    * @param _fullpath full path to the config file
  87.    * @param _relpath relative path to the config file
  88.    */
  89.   KServiceGroup( const QString & _fullpath, const QString & _relpath );
  90.  
  91.   /**
  92.    * @internal construct a service from a stream.
  93.    * The stream must already be positionned at the correct offset
  94.    */
  95.   KServiceGroup( QDataStream& _str, int offset, bool deep );
  96.  
  97.   virtual ~KServiceGroup();
  98.  
  99.   /**
  100.    * Checks whether the entry is valid, returns always true.
  101.    * @return true
  102.    */
  103.   bool isValid() const { return true; }
  104.  
  105.   /**
  106.    * Name used for indexing.
  107.    * @return the service group's name
  108.    */
  109.   virtual QString name() const { return entryPath(); }
  110.  
  111.   /**
  112.    * Returns the relative path of the service group.
  113.    * @return the service group's relative path
  114.    */
  115.   virtual QString relPath() const { return entryPath(); }
  116.  
  117.   /**
  118.    * Returns the caption of this group.
  119.    * @return the caption of this group
  120.    */
  121.   QString caption() const { return m_strCaption; }
  122.  
  123.   /**
  124.    * Returns the name of the icon associated with the group.
  125.    * @return the name of the icon associated with the group,
  126.    *         or QString::null if not set
  127.    */
  128.   QString icon() const { return m_strIcon; }
  129.  
  130.   /**
  131.    * Returns the comment about this service group.
  132.    * @return the descriptive comment for the group, if there is one,
  133.    *         or QString::null if not set
  134.    */
  135.   QString comment() const { return m_strComment; }
  136.  
  137.   /**
  138.    * Returns the total number of displayable services in this group and
  139.    * any of its subgroups.
  140.    * @return the number of child services
  141.    */
  142.   int childCount();
  143.  
  144.   /**
  145.    * Returns true if the NoDisplay flag was set, i.e. if this
  146.    * group should be hidden from menus, while still being in ksycoca.
  147.    * @return true to hide this service group, false to display it
  148.    * @since 3.1
  149.    */
  150.   bool noDisplay() const;
  151.  
  152.   /**
  153.    * Return true if we want to display empty menu entry
  154.    * @return true to show this service group as menu entry is empty, false to hide it
  155.    * @since 3.4
  156.    */
  157.   bool showEmptyMenu() const;
  158.   void setShowEmptyMenu( bool b);
  159.  
  160.   /**
  161.    * @return true to show an inline header into menu
  162.    * @since 3.5
  163.    */
  164.   bool showInlineHeader() const;
  165.   void setShowInlineHeader(bool _b);
  166.  
  167.   /**
  168.    * @return true to show an inline alias item into menu
  169.    * @since 3.5
  170.    */
  171.   bool inlineAlias() const;
  172.   void setInlineAlias(bool _b);
  173.   /**
  174.    * @return true if we allow to inline menu.
  175.    * @since 3.5
  176.    */
  177.   bool allowInline() const;
  178.   void setAllowInline(bool _b);
  179.  
  180.   /**
  181.    * @return inline limite value
  182.    * @since 3.5
  183.    */
  184.   int inlineValue() const;
  185.   void setInlineValue(int _val);
  186.  
  187.  
  188.   /**
  189.    * Returns a list of untranslated generic names that should be
  190.    * be supressed when showing this group.
  191.    * E.g. The group "Games/Arcade" might want to suppress the generic name
  192.    * "Arcade Game" since it's redundant in this particular context.
  193.    * @since 3.2
  194.    */
  195.   QStringList suppressGenericNames() const;
  196.  
  197.   /**
  198.    * @internal
  199.    * Sets information related to the layout of services in this group.
  200.    */
  201.   void setLayoutInfo(const QStringList &layout);
  202.  
  203.   /**
  204.    * @internal
  205.    * Returns information related to the layout of services in this group.
  206.    */
  207.   QStringList layoutInfo() const;
  208.  
  209.   /**
  210.    * @internal
  211.    * Load the service from a stream.
  212.    */
  213.   virtual void load( QDataStream& );
  214.   /**
  215.    * @internal
  216.    * Save the service to a stream.
  217.    */
  218.   virtual void save( QDataStream& );
  219.  
  220.   /**
  221.    * List of all Services and ServiceGroups within this
  222.    * ServiceGroup.
  223.    * @param sorted true to sort items
  224.    * @param excludeNoDisplay true to exclude items marked "NoDisplay"
  225.    * @param allowSeparators true to allow separator items to be included
  226.    * @param sortByGenericName true to sort GenericName+Name instead of Name+GenericName
  227.    * @return the list of entries
  228.    * @since 3.2
  229.    */
  230.   List entries(bool sorted, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName=false);
  231.   virtual List entries(bool sorted, bool excludeNoDisplay);
  232.  
  233.   /**
  234.    * List of all Services and ServiceGroups within this
  235.    * ServiceGroup.
  236.    * @param sorted true to sort items
  237.    * @return the list of entried
  238.    */
  239.   virtual List entries(bool sorted = false);
  240.  
  241.   /**
  242.    * Returns a non-empty string if the group is a special base group.
  243.    * By default, "Settings/" is the kcontrol base group ("settings")
  244.    * and "System/Screensavers/" is the screensavers base group ("screensavers").
  245.    * This allows moving the groups without breaking those apps.
  246.    *
  247.    * The base group is defined by the X-KDE-BaseGroup key
  248.    * in the .directory file.
  249.    * @return the base group name, or null if no base group
  250.    */
  251.   QString baseGroupName() const { return m_strBaseGroupName; }
  252.  
  253.   /**
  254.    * Returns a path to the .directory file describing this service group.
  255.    * The path is either absolute or relative to the "apps" resource.
  256.    * @since 3.2
  257.    */
  258.   QString directoryEntryPath() const;
  259.  
  260.   /**
  261.    * Returns the group for the given baseGroupName.
  262.    * Can return 0L if the directory (or the .directory file) was deleted.
  263.    * @return the base group with the given name, or 0 if not available.
  264.    */
  265.   static Ptr baseGroup( const QString &baseGroupName );
  266.  
  267.   /**
  268.    * Returns the root service group.
  269.    * @return the root service group
  270.    */
  271.   static Ptr root();
  272.  
  273.   /**
  274.    * Returns the group with the given relative path.
  275.    * @param relPath the path of the service group
  276.    * @return the group with the given relative path name.
  277.    */
  278.   static Ptr group(const QString &relPath);
  279.  
  280.   /**
  281.    * Returns the group of services that have X-KDE-ParentApp equal
  282.    * to @p parent (siblings).
  283.    * @param parent the name of the service's parent
  284.    * @return the services group
  285.    * @since 3.1
  286.    */
  287.   static Ptr childGroup(const QString &parent);
  288.  
  289.   /**
  290.    * This function parse attributes into menu
  291.    * @since 3.5
  292.    */
  293.     void parseAttribute( const QString &item ,  bool &showEmptyMenu, bool &showInline, bool &showInlineHeader, bool & showInlineAlias ,int &inlineValue );
  294.  
  295. protected:
  296.   /**
  297.    * @internal
  298.    * Add a service to this group
  299.    */
  300.   void addEntry( KSycocaEntry *entry);
  301.  
  302.   QString m_strCaption;
  303.   QString m_strIcon;
  304.   QString m_strComment;
  305.  
  306.   List m_serviceList;
  307.   bool m_bDeep;
  308.   QString m_strBaseGroupName;
  309.   int m_childCount;
  310. protected:
  311.   virtual void virtual_hook( int id, void* data );
  312. private:
  313.   class Private;
  314.   Private* d;
  315. };
  316.  
  317. class KIO_EXPORT KServiceSeparator : public KSycocaEntry
  318. {
  319.   K_SYCOCATYPE( KST_KServiceSeparator, KSycocaEntry )
  320.  
  321. public:
  322.   typedef KSharedPtr<KServiceSeparator> Ptr;
  323. public:
  324.   /**
  325.    * Construct a service separator
  326.    * @since 3.2
  327.    */
  328.   KServiceSeparator();
  329.  
  330.   bool isValid() const { return true; }
  331.  
  332.   // Dummy
  333.   virtual QString name() const { return "separator"; }
  334.   // Dummy
  335.   virtual void load( QDataStream& ) { };
  336.   // Dummy
  337.   virtual void save( QDataStream& ) { };
  338. };
  339.  
  340. #endif
  341.