File indexing completed on 2024-11-10 12:25:49

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0004     SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef __kservicetype_h__
0010 #define __kservicetype_h__
0011 
0012 #include <ksycocaentry.h>
0013 
0014 #include <QMap>
0015 #include <QString>
0016 #include <QStringList>
0017 #include <QVariant>
0018 
0019 #include <KConfig>
0020 
0021 class KDesktopFile;
0022 class KServiceTypePrivate;
0023 
0024 /**
0025  * @class KServiceType kservicetype.h <KServiceType>
0026  *
0027  * A service type is, well, a type of service, where a service is an application or plugin.
0028  * For instance, "KOfficeFilter", which is the type of all koffice filters, is a service type.
0029  * In order to discover services of a given type, using KServiceTypeTrader.
0030  * Service types are stored as desktop files in $KDEDIR/share/servicetypes.
0031  * @see KService, KServiceTypeTrader
0032  * @deprecated Since  5.90, this class is an implementation detail of KService.
0033  * Use @ref KService or @ref KApplicationTrader instead.
0034  */
0035 class KSERVICE_EXPORT KServiceType : public KSycocaEntry // TODO KDE5: inherit kshared, but move KSycocaEntry to KServiceTypePrivate
0036 {
0037 public:
0038     /**
0039      * A shared data pointer for KServiceType.
0040      */
0041     typedef QExplicitlySharedDataPointer<KServiceType> Ptr;
0042     /**
0043      * A list of shared data pointers for KServiceType.
0044      */
0045     typedef QList<Ptr> List;
0046 
0047     /**
0048      * Construct a service type and take all information from a desktop file.
0049      * @param config the configuration file
0050      * @deprecated Since 5.90, see class API docs
0051      */
0052     KSERVICE_DEPRECATED_VERSION(5, 90, "See class API docs")
0053     explicit KServiceType(KDesktopFile *config);
0054 
0055     ~KServiceType() override;
0056 
0057     /**
0058      * Returns the descriptive comment associated, if any.
0059      * @return the comment, or QString()
0060      */
0061     QString comment() const;
0062 
0063     /**
0064      * Checks whether this service type inherits another one.
0065      * @return true if this service type inherits another one
0066      * @see parentServiceType()
0067      */
0068     bool isDerived() const;
0069 
0070     /**
0071      * If this service type inherits from another service type,
0072      * return the name of the parent.
0073      * @return the parent service type, or QString:: null if not set
0074      * @see isDerived()
0075      */
0076     QString parentServiceType() const;
0077 
0078     /**
0079      * Checks whether this service type is or inherits from @p servTypeName.
0080      * @return true if this servicetype is or inherits from @p servTypeName
0081      */
0082     bool inherits(const QString &servTypeName) const;
0083 
0084     /**
0085      * Returns the type of the property definition with the given @p _name.
0086      *
0087      * @param _name the name of the property
0088      * @return the property type, or null if not found
0089      * @see propertyDefNames
0090      */
0091     QVariant::Type propertyDef(const QString &_name) const;
0092 
0093     /**
0094      * Returns the list of all property definitions for this servicetype.
0095      * Those are properties of the services implementing this servicetype.
0096      * For instance,
0097      * @code
0098      * [PropertyDef::X-KDevelop-Version]
0099      * Type=int
0100      * @endcode
0101      * means that all kdevelop plugins have in their .desktop file a line like
0102      * @code
0103      * X-KDevelop-Version=<some value>
0104      * @endcode
0105      */
0106     QStringList propertyDefNames() const;
0107 
0108     /// @internal (for KBuildServiceTypeFactory)
0109     QMap<QString, QVariant::Type> propertyDefs() const;
0110 
0111     /**
0112      * @internal
0113      * Pointer to parent service type
0114      */
0115     Ptr parentType();
0116     /**
0117      * @internal  only used by kbuildsycoca
0118      * Register offset into offers list
0119      */
0120     void setServiceOffersOffset(int offset);
0121     /**
0122      * @internal
0123      */
0124     int serviceOffersOffset() const;
0125 
0126     /**
0127      * Returns a pointer to the servicetype '_name' or @c nullptr if the
0128      *         service type is unknown.
0129      * VERY IMPORTANT : don't store the result in a KServiceType * !
0130      * @param _name the name of the service type to search
0131      * @return the pointer to the service type, or @c nullptr
0132      */
0133     static Ptr serviceType(const QString &_name);
0134 
0135     /**
0136      * Returns a list of all the supported servicetypes. Useful for
0137      *         showing the list of available servicetypes in a listbox,
0138      *         for example.
0139      * More memory consuming than the ones above, don't use unless
0140      * really necessary.
0141      * @return the list of all services
0142      */
0143     static List allServiceTypes();
0144 
0145 private:
0146     friend class KServiceTypeFactory;
0147     /**
0148      * @internal construct a service from a stream.
0149      * The stream must already be positioned at the correct offset
0150      */
0151     KServiceType(QDataStream &_str, int offset);
0152 
0153     Q_DECLARE_PRIVATE(KServiceType)
0154 };
0155 
0156 // QDataStream& operator>>( QDataStream& _str, KServiceType& s );
0157 // QDataStream& operator<<( QDataStream& _str, KServiceType& s );
0158 
0159 #endif