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
16class 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 * @see KService
28 * @short Holds the user's preference of a service.
29 */
30class KSERVICE_EXPORT KServiceOffer // exported for kbuildsycoca
31{
32public:
33 /**
34 * Create an invalid service offer.
35 */
36 KServiceOffer();
37
38 /**
39 * Copy constructor.
40 * Shallow copy (the KService will not be copied).
41 */
42 KServiceOffer(const KServiceOffer &);
43
44 /**
45 * Creates a new KServiceOffer.
46 * @param service a pointer to the KService
47 * @param pref the user's preference value, must be positive,
48 * bigger is better
49 * @param 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 * @since 5.71
53 */
54 KServiceOffer(const KService::Ptr &service, int pref, int mimeTypeInheritanceLevel);
55
56 ~KServiceOffer();
57
58 /**
59 * A service is bigger that the other when it can be default
60 * (and the other is not) and its preference value it higher.
61 */
62 bool operator<(const KServiceOffer &) const;
63
64 /**
65 * Assignment operator
66 */
67 KServiceOffer &operator=(const KServiceOffer &other);
68
69 /**
70 * The bigger this number is, the better is this service.
71 * @return the preference number (negative numbers will be
72 * returned by invalid service offers)
73 */
74 int preference() const;
75
76 /**
77 * The bigger this number is, the better is this service.
78 * Set the preference number
79 * @internal - only for KMimeTypeTrader
80 */
81 void setPreference(int p);
82
83 /**
84 * The service which this offer is about.
85 * @return the service this offer is about, can be @c nullptr
86 * in valid offers or when not set
87 */
88 KService::Ptr service() const;
89
90 /**
91 * Check whether the entry is valid. A service is valid if
92 * its preference value is positive.
93 * @return true if the service offer is valid
94 */
95 bool isValid() const;
96
97 /**
98 * When copying an offer from a parent MIME type, remember that it's an inherited capability
99 * (for sorting purposes; we prefer a handler for postscript over any text/plain handler)
100 */
101 void setMimeTypeInheritanceLevel(int level);
102
103 /**
104 * Mimetype inheritance level
105 * @internal
106 */
107 int mimeTypeInheritanceLevel() const;
108
109private:
110 std::unique_ptr<KServiceOfferPrivate> const d;
111};
112
113/**
114 * A list of weighted offers.
115 */
116typedef QList<KServiceOffer> KServiceOfferList;
117
118QDebug operator<<(QDebug dbg, const KServiceOffer &offer);
119
120#endif /* KSERVICEOFFER_H */
121

source code of kservice/src/services/kserviceoffer.h