File indexing completed on 2024-04-28 15:29:55

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 1999 Waldo Bastian <bastian@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KSYCOCAENTRY_H
0009 #define KSYCOCAENTRY_H
0010 
0011 #include <kservice_export.h>
0012 #include <ksycocatype.h>
0013 
0014 #include <QDataStream>
0015 #include <QExplicitlySharedDataPointer>
0016 #include <QStringList>
0017 #include <QVariant>
0018 
0019 #include <memory>
0020 
0021 class KSycocaEntryPrivate;
0022 
0023 /**
0024  * Base class for all Sycoca entries.
0025  *
0026  * You can't create an instance of KSycocaEntry, but it provides
0027  * the common functionality for servicetypes and services.
0028  *
0029  * @internal
0030  * @see http://techbase.kde.org/Development/Architecture/KDE3/System_Configuration_Cache
0031  */
0032 class KSERVICE_EXPORT KSycocaEntry : public QSharedData
0033 {
0034 public:
0035     /*
0036      * constructs a invalid KSycocaEntry object
0037      */
0038     KSycocaEntry();
0039 
0040     virtual ~KSycocaEntry();
0041 
0042     /**
0043      * Returns true if this sycoca entry is of the given type.
0044      */
0045     bool isType(KSycocaType t) const;
0046     /**
0047      * internal
0048      */
0049     KSycocaType sycocaType() const;
0050 
0051     /**
0052      * A shared data pointer for KSycocaEntry.
0053      */
0054     typedef QExplicitlySharedDataPointer<KSycocaEntry> Ptr;
0055     /**
0056      * A list of shared data pointers for KSycocaEntry.
0057      */
0058     typedef QList<Ptr> List;
0059 
0060     /**
0061      * @return the name of this entry
0062      */
0063     QString name() const;
0064 
0065     /**
0066      * @return the path of this entry
0067      * The path can be absolute or relative.
0068      * The corresponding factory should know relative to what.
0069      */
0070     QString entryPath() const;
0071 
0072     /**
0073      * @return the unique ID for this entry
0074      * In practice, this is storageId() for KService and name() for everything else.
0075      * \since 4.2.1
0076      */
0077     QString storageId() const;
0078 
0079     /**
0080      * @return true if valid
0081      */
0082     bool isValid() const;
0083 
0084     /**
0085      * @return true if deleted
0086      */
0087     bool isDeleted() const;
0088 
0089     /**
0090      * Returns the requested property. Some often used properties
0091      * have convenience access functions like exec(),
0092      * serviceTypes etc.
0093      *
0094      * @param name the name of the property
0095      * @return the property, or invalid if not found
0096      */
0097     QVariant property(const QString &name) const;
0098 
0099     /**
0100      * Returns the list of all properties that this service can have.
0101      * That means, that some of these properties may be empty.
0102      * @return the list of supported properties
0103      */
0104     QStringList propertyNames() const;
0105 
0106     /**
0107      * Sets whether or not this service is deleted
0108      */
0109     void setDeleted(bool deleted);
0110 
0111     /**
0112      * @returns true, if this is a separator
0113      */
0114     bool isSeparator() const;
0115 
0116 protected:
0117     KSERVICE_NO_EXPORT explicit KSycocaEntry(KSycocaEntryPrivate &d);
0118     std::unique_ptr<KSycocaEntryPrivate> const d_ptr;
0119 
0120 private:
0121     // All these need access to offset()
0122     friend class KSycocaFactory;
0123     friend class KBuildServiceFactory;
0124     friend class KServiceFactory;
0125     friend class KMimeTypeTrader;
0126     friend class KServiceTypeTrader;
0127     friend class KService;
0128     friend class KSycocaDict;
0129     friend class KSycocaDictTest;
0130 
0131     /**
0132      * @internal
0133      * @return the position of the entry in the sycoca file
0134      */
0135     int offset() const;
0136     // exported for KSycocaDictTest
0137 
0138     Q_DISABLE_COPY(KSycocaEntry)
0139 
0140     Q_DECLARE_PRIVATE(KSycocaEntry)
0141 };
0142 
0143 #endif