File indexing completed on 2024-10-06 03:41:01

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      * Sets whether or not this service is deleted
0091      */
0092     void setDeleted(bool deleted);
0093 
0094     /**
0095      * @returns true, if this is a separator
0096      */
0097     bool isSeparator() const;
0098 
0099 protected:
0100     KSERVICE_NO_EXPORT explicit KSycocaEntry(KSycocaEntryPrivate &d);
0101     std::unique_ptr<KSycocaEntryPrivate> const d_ptr;
0102 
0103 private:
0104     // All these need access to offset()
0105     friend class KSycocaFactory;
0106     friend class KBuildServiceFactory;
0107     friend class KServiceFactory;
0108     friend class KService;
0109     friend class KSycocaDict;
0110     friend class KSycocaDictTest;
0111 
0112     /**
0113      * @internal
0114      * @return the position of the entry in the sycoca file
0115      */
0116     KSERVICE_NO_EXPORT int offset() const;
0117 
0118     Q_DISABLE_COPY(KSycocaEntry)
0119 
0120     Q_DECLARE_PRIVATE(KSycocaEntry)
0121 };
0122 
0123 #endif