KService

kserviceoffer.cpp
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#include "kserviceoffer.h"
10
11#include <QDebug>
12
13class KServiceOfferPrivate
14{
15public:
16 KServiceOfferPrivate()
17 : preference(-1)
18 , mimeTypeInheritanceLevel(0)
19 , pService(nullptr)
20 {
21 }
22
23 int preference;
24 int mimeTypeInheritanceLevel;
25 KService::Ptr pService;
26};
27
29 : d(new KServiceOfferPrivate)
30{
31}
32
34 : d(new KServiceOfferPrivate)
35{
36 *d = *_o.d;
37}
38
39KServiceOffer::KServiceOffer(const KService::Ptr &_service, int _pref, int mimeTypeInheritanceLevel)
40 : d(new KServiceOfferPrivate)
41{
42 d->pService = _service;
43 d->preference = _pref;
44 d->mimeTypeInheritanceLevel = mimeTypeInheritanceLevel;
45}
46
47KServiceOffer::~KServiceOffer() = default;
48
50{
51 if (this == &rhs) {
52 return *this;
53 }
54
55 *d = *rhs.d;
56 return *this;
57}
58
60{
61 // First check mimetype inheritance level.
62 // Direct mimetype association is preferred above association via parent mimetype
63 // So, the smaller the better.
64 if (d->mimeTypeInheritanceLevel != _o.d->mimeTypeInheritanceLevel) {
65 return d->mimeTypeInheritanceLevel < _o.d->mimeTypeInheritanceLevel;
66 }
67
68 // Finally, use preference to sort them
69 // The bigger the better, but we want the better FIRST
70 return _o.d->preference < d->preference;
71}
72
74{
75 return d->preference;
76}
77
79{
80 d->preference = p;
81}
82
84{
85 return d->pService;
86}
87
89{
90 return d->preference >= 0;
91}
92
94{
95 d->mimeTypeInheritanceLevel = level;
96}
97
99{
100 return d->mimeTypeInheritanceLevel;
101}
102
103QDebug operator<<(QDebug dbg, const KServiceOffer &offer)
104{
105 QDebugStateSaver saver(dbg);
106 dbg.nospace() << offer.service()->storageId() << " " << offer.preference();
107 if (offer.mimeTypeInheritanceLevel() > 0) {
108 dbg << " (inheritance level " << offer.mimeTypeInheritanceLevel() << ")";
109 }
110 return dbg;
111}
Holds the user's preference of a service.
int mimeTypeInheritanceLevel() const
Mimetype inheritance level.
void setPreference(int p)
The bigger this number is, the better is this service.
void setMimeTypeInheritanceLevel(int level)
When copying an offer from a parent MIME type, remember that it's an inherited capability (for sortin...
KServiceOffer & operator=(const KServiceOffer &other)
Assignment operator.
bool operator<(const KServiceOffer &) const
A service is bigger that the other when it can be default (and the other is not) and its preference v...
bool isValid() const
Check whether the entry is valid.
KServiceOffer()
Create an invalid service offer.
int preference() const
The bigger this number is, the better is this service.
KService::Ptr service() const
The service which this offer is about.
QDebug & nospace()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.