| 1 | /* |
| 2 | This file is part of the KDE libraries |
| 3 | SPDX-FileCopyrightText: 2000 Torben Weis <weis@kde.org> |
| 4 | SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 | */ |
| 8 | |
| 9 | #ifndef KSERVICEOFFER_H |
| 10 | #define KSERVICEOFFER_H |
| 11 | |
| 12 | #include <kservice.h> |
| 13 | |
| 14 | #include <memory> |
| 15 | |
| 16 | class KServiceOfferPrivate; |
| 17 | |
| 18 | /*! |
| 19 | * \internal |
| 20 | * |
| 21 | * This class holds the user-specific preferences of a service |
| 22 | * (whether it can be a default offer or not, how big is the preference |
| 23 | * for this offer, ...). Basically it is a reference to a |
| 24 | * KService, a number that represents the user's preference (bigger |
| 25 | * is better) and a flag whether the KService can be used as default. |
| 26 | */ |
| 27 | class KSERVICE_EXPORT KServiceOffer // exported for kbuildsycoca |
| 28 | { |
| 29 | public: |
| 30 | /*! |
| 31 | * Create an invalid service offer. |
| 32 | */ |
| 33 | KServiceOffer(); |
| 34 | |
| 35 | /*! |
| 36 | * Copy constructor. |
| 37 | * Shallow copy (the KService will not be copied). |
| 38 | */ |
| 39 | KServiceOffer(const KServiceOffer &); |
| 40 | |
| 41 | /*! |
| 42 | * Creates a new KServiceOffer. |
| 43 | * |
| 44 | * \a service a pointer to the KService |
| 45 | * |
| 46 | * \a pref the user's preference value, must be positive, |
| 47 | * bigger is better |
| 48 | * |
| 49 | * \a mimeTypeInheritanceLevel level of MIME type inheritance |
| 50 | * which allows this service to handling the MIME type. |
| 51 | * 0 if no inheritance involved, 1 for parent MIME type, etc. |
| 52 | * |
| 53 | * \since 5.71 |
| 54 | */ |
| 55 | KServiceOffer(const KService::Ptr &service, int pref, int mimeTypeInheritanceLevel); |
| 56 | |
| 57 | ~KServiceOffer(); |
| 58 | |
| 59 | /*! |
| 60 | * A service is bigger that the other when it can be default |
| 61 | * (and the other is not) and its preference value it higher. |
| 62 | */ |
| 63 | bool operator<(const KServiceOffer &) const; |
| 64 | |
| 65 | /*! |
| 66 | * Assignment operator |
| 67 | */ |
| 68 | KServiceOffer &operator=(const KServiceOffer &other); |
| 69 | |
| 70 | /*! |
| 71 | * The bigger this number is, the better is this service. |
| 72 | * |
| 73 | * Returns the preference number (negative numbers will be |
| 74 | * returned by invalid service offers) |
| 75 | */ |
| 76 | int preference() const; |
| 77 | |
| 78 | /*! |
| 79 | * The bigger this number is, the better is this service. |
| 80 | * Set the preference number |
| 81 | * \internal - only for KMimeTypeTrader |
| 82 | */ |
| 83 | void setPreference(int p); |
| 84 | |
| 85 | /*! |
| 86 | * The service which this offer is about. |
| 87 | * Returns the service this offer is about, can be \c nullptr |
| 88 | * in valid offers or when not set |
| 89 | */ |
| 90 | KService::Ptr service() const; |
| 91 | |
| 92 | /*! |
| 93 | * Check whether the entry is valid. A service is valid if |
| 94 | * its preference value is positive. |
| 95 | * |
| 96 | * Returns true if the service offer is valid |
| 97 | */ |
| 98 | bool isValid() const; |
| 99 | |
| 100 | /*! |
| 101 | * When copying an offer from a parent MIME type, remember that it's an inherited capability |
| 102 | * (for sorting purposes; we prefer a handler for postscript over any text/plain handler) |
| 103 | */ |
| 104 | void setMimeTypeInheritanceLevel(int level); |
| 105 | |
| 106 | /*! |
| 107 | * Mimetype inheritance level |
| 108 | * \internal |
| 109 | */ |
| 110 | int mimeTypeInheritanceLevel() const; |
| 111 | |
| 112 | private: |
| 113 | std::unique_ptr<KServiceOfferPrivate> const d; |
| 114 | }; |
| 115 | |
| 116 | typedef QList<KServiceOffer> KServiceOfferList; |
| 117 | |
| 118 | QDebug operator<<(QDebug dbg, const KServiceOffer &offer); |
| 119 | |
| 120 | #endif /* KSERVICEOFFER_H */ |
| 121 | |