File indexing completed on 2023-09-24 04:11:09
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2000 Torben Weis <weis@kde.org> 0004 SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KSERVICEOFFER_H 0010 #define KSERVICEOFFER_H 0011 0012 #include <kservice.h> 0013 0014 #include <memory> 0015 0016 class KServiceOfferPrivate; 0017 0018 /** 0019 * @internal 0020 * 0021 * This class holds the user-specific preferences of a service 0022 * (whether it can be a default offer or not, how big is the preference 0023 * for this offer, ...). Basically it is a reference to a 0024 * KService, a number that represents the user's preference (bigger 0025 * is better) and a flag whether the KService can be used as default. 0026 * 0027 * @see KService 0028 * @short Holds the user's preference of a service. 0029 */ 0030 class KSERVICE_EXPORT KServiceOffer // exported for kbuildsycoca 0031 { 0032 public: 0033 /** 0034 * Create an invalid service offer. 0035 */ 0036 KServiceOffer(); 0037 0038 /** 0039 * Copy constructor. 0040 * Shallow copy (the KService will not be copied). 0041 */ 0042 KServiceOffer(const KServiceOffer &); 0043 0044 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 71) 0045 /** 0046 * Creates a new KServiceOffer. 0047 * @param service a pointer to the KService 0048 * @param pref the user's preference value, must be positive, 0049 * bigger is better 0050 * @param mimeTypeInheritanceLevel level of MIME type inheritance 0051 * which allows this service to handling the MIME type. 0052 * 0 if no inheritance involved, 1 for parent MIME type, etc. 0053 * @param allowedAsDefault true if the service should be used as 0054 * default 0055 * @deprecated Since 5.71, use constructor without @p allowedAsDefault argument 0056 */ 0057 KSERVICE_DEPRECATED_VERSION(5, 71, "Use constructor without allowedAsDefault argument") 0058 KServiceOffer(const KService::Ptr &service, int pref, int mimeTypeInheritanceLevel, bool allowedAsDefault); 0059 #endif 0060 0061 /** 0062 * Creates a new KServiceOffer. 0063 * @param service a pointer to the KService 0064 * @param pref the user's preference value, must be positive, 0065 * bigger is better 0066 * @param mimeTypeInheritanceLevel level of MIME type inheritance 0067 * which allows this service to handling the MIME type. 0068 * 0 if no inheritance involved, 1 for parent MIME type, etc. 0069 * @since 5.71 0070 */ 0071 KServiceOffer(const KService::Ptr &service, int pref, int mimeTypeInheritanceLevel); 0072 0073 ~KServiceOffer(); 0074 0075 /** 0076 * A service is bigger that the other when it can be default 0077 * (and the other is not) and its preference value it higher. 0078 */ 0079 bool operator<(const KServiceOffer &) const; 0080 0081 /** 0082 * Assignment operator 0083 */ 0084 KServiceOffer &operator=(const KServiceOffer &other); 0085 0086 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 67) 0087 /** 0088 * Is it allowed to use this service for default actions 0089 * (e.g. Left Click in a file manager, or KRun in general). 0090 * @return true if the service is a allowed as default 0091 * @deprecated since 5.67, no know use case. 0092 */ 0093 KSERVICE_DEPRECATED_VERSION(5, 67, "No known use case") 0094 bool allowAsDefault() const; 0095 #endif 0096 0097 /** 0098 * The bigger this number is, the better is this service. 0099 * @return the preference number (negative numbers will be 0100 * returned by invalid service offers) 0101 */ 0102 int preference() const; 0103 0104 /** 0105 * The bigger this number is, the better is this service. 0106 * Set the preference number 0107 * @internal - only for KMimeTypeTrader 0108 */ 0109 void setPreference(int p); 0110 0111 /** 0112 * The service which this offer is about. 0113 * @return the service this offer is about, can be @c nullptr 0114 * in valid offers or when not set 0115 */ 0116 KService::Ptr service() const; 0117 0118 /** 0119 * Check whether the entry is valid. A service is valid if 0120 * its preference value is positive. 0121 * @return true if the service offer is valid 0122 */ 0123 bool isValid() const; 0124 0125 /** 0126 * When copying an offer from a parent MIME type, remember that it's an inherited capability 0127 * (for sorting purposes; we prefer a handler for postscript over any text/plain handler) 0128 */ 0129 void setMimeTypeInheritanceLevel(int level); 0130 0131 /** 0132 * Mimetype inheritance level 0133 * @internal 0134 */ 0135 int mimeTypeInheritanceLevel() const; 0136 0137 private: 0138 std::unique_ptr<KServiceOfferPrivate> const d; 0139 }; 0140 0141 /** 0142 * A list of weighted offers. 0143 */ 0144 typedef QList<KServiceOffer> KServiceOfferList; 0145 0146 QDebug operator<<(QDebug dbg, const KServiceOffer &offer); 0147 0148 #endif /* KSERVICEOFFER_H */