File indexing completed on 2024-07-21 03:42:34

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     /**
0045      * Creates a new KServiceOffer.
0046      * @param service a pointer to the KService
0047      * @param pref the user's preference value, must be positive,
0048      *              bigger is better
0049      * @param mimeTypeInheritanceLevel level of MIME type inheritance
0050      *       which allows this service to handling the MIME type.
0051      *       0 if no inheritance involved, 1 for parent MIME type, etc.
0052      * @since 5.71
0053      */
0054     KServiceOffer(const KService::Ptr &service, int pref, int mimeTypeInheritanceLevel);
0055 
0056     ~KServiceOffer();
0057 
0058     /**
0059      * A service is bigger that the other when it can be default
0060      * (and the other is not) and its preference value it higher.
0061      */
0062     bool operator<(const KServiceOffer &) const;
0063 
0064     /**
0065      * Assignment operator
0066      */
0067     KServiceOffer &operator=(const KServiceOffer &other);
0068 
0069     /**
0070      * The bigger this number is, the better is this service.
0071      * @return the preference number (negative numbers will be
0072      *         returned by invalid service offers)
0073      */
0074     int preference() const;
0075 
0076     /**
0077      * The bigger this number is, the better is this service.
0078      * Set the preference number
0079      * @internal - only for KMimeTypeTrader
0080      */
0081     void setPreference(int p);
0082 
0083     /**
0084      * The service which this offer is about.
0085      * @return the service this offer is about, can be @c nullptr
0086      *         in valid offers or when not set
0087      */
0088     KService::Ptr service() const;
0089 
0090     /**
0091      * Check whether the entry is valid. A service is valid if
0092      * its preference value is positive.
0093      * @return true if the service offer is valid
0094      */
0095     bool isValid() const;
0096 
0097     /**
0098      * When copying an offer from a parent MIME type, remember that it's an inherited capability
0099      * (for sorting purposes; we prefer a handler for postscript over any text/plain handler)
0100      */
0101     void setMimeTypeInheritanceLevel(int level);
0102 
0103     /**
0104      * Mimetype inheritance level
0105      * @internal
0106      */
0107     int mimeTypeInheritanceLevel() const;
0108 
0109 private:
0110     std::unique_ptr<KServiceOfferPrivate> const d;
0111 };
0112 
0113 /**
0114  * A list of weighted offers.
0115  */
0116 typedef QList<KServiceOffer> KServiceOfferList;
0117 
0118 QDebug operator<<(QDebug dbg, const KServiceOffer &offer);
0119 
0120 #endif /* KSERVICEOFFER_H */