• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • services
kserviceoffer.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2000 Torben Weis <weis@kde.org>
3 Copyright (C) 2006 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#include "kserviceoffer.h"
21
22class KServiceOffer::Private
23{
24public:
25 Private()
26 : preference(-1),
27 mimeTypeInheritanceLevel(0),
28 bAllowAsDefault( false ),
29 pService( 0 )
30 {
31 }
32
33 int preference;
34 int mimeTypeInheritanceLevel;
35 bool bAllowAsDefault;
36 KService::Ptr pService;
37};
38
39KServiceOffer::KServiceOffer()
40 : d( new Private )
41{
42}
43
44KServiceOffer::KServiceOffer( const KServiceOffer& _o )
45 : d( new Private )
46{
47 *d = *_o.d;
48}
49
50KServiceOffer::KServiceOffer( const KService::Ptr& _service, int _pref, int mimeTypeInheritanceLevel, bool _default )
51 : d( new Private )
52{
53 d->pService = _service;
54 d->preference = _pref;
55 d->mimeTypeInheritanceLevel = mimeTypeInheritanceLevel;
56 d->bAllowAsDefault = _default;
57}
58
59KServiceOffer::~KServiceOffer()
60{
61 delete d;
62}
63
64KServiceOffer& KServiceOffer::operator=( const KServiceOffer& rhs )
65{
66 if ( this == &rhs ) {
67 return *this;
68 }
69
70 *d = *rhs.d;
71 return *this;
72}
73
74bool KServiceOffer::operator< ( const KServiceOffer& _o ) const
75{
76 // First check mimetype inheritance level.
77 // Direct mimetype association is preferred above association via parent mimetype
78 // So, the smaller the better.
79 if (d->mimeTypeInheritanceLevel != _o.d->mimeTypeInheritanceLevel)
80 return d->mimeTypeInheritanceLevel < _o.d->mimeTypeInheritanceLevel;
81
82 // Put offers allowed as default FIRST.
83 if ( _o.d->bAllowAsDefault && !d->bAllowAsDefault )
84 return false; // _o is default and not 'this'.
85 if ( !_o.d->bAllowAsDefault && d->bAllowAsDefault )
86 return true; // 'this' is default but not _o.
87 // Both offers are allowed or not allowed as default
88
89 // Finally, use preference to sort them
90 // The bigger the better, but we want the better FIRST
91 return _o.d->preference < d->preference;
92}
93
94bool KServiceOffer::allowAsDefault() const
95{
96 return d->bAllowAsDefault;
97}
98
99int KServiceOffer::preference() const
100{
101 return d->preference;
102}
103
104void KServiceOffer::setPreference( int p )
105{
106 d->preference = p;
107}
108
109KService::Ptr KServiceOffer::service() const
110{
111 return d->pService;
112}
113
114bool KServiceOffer::isValid() const
115{
116 return d->preference >= 0;
117}
118
119void KServiceOffer::setMimeTypeInheritanceLevel(int level)
120{
121 d->mimeTypeInheritanceLevel = level;
122}
123
124int KServiceOffer::mimeTypeInheritanceLevel() const
125{
126 return d->mimeTypeInheritanceLevel;
127}
128
KServiceOffer
Holds the user's preference of a service.
Definition: kserviceoffer.h:39
KServiceOffer::mimeTypeInheritanceLevel
int mimeTypeInheritanceLevel() const
Mimetype inheritance level.
Definition: kserviceoffer.cpp:124
KServiceOffer::allowAsDefault
bool allowAsDefault() const
Is it allowed to use this service for default actions (e.g.
Definition: kserviceoffer.cpp:94
KServiceOffer::setPreference
void setPreference(int p)
The bigger this number is, the better is this service.
Definition: kserviceoffer.cpp:104
KServiceOffer::~KServiceOffer
~KServiceOffer()
Definition: kserviceoffer.cpp:59
KServiceOffer::setMimeTypeInheritanceLevel
void setMimeTypeInheritanceLevel(int level)
When copying an offer from a parent mimetype, remember that it's an inherited capability (for sorting...
Definition: kserviceoffer.cpp:119
KServiceOffer::operator=
KServiceOffer & operator=(const KServiceOffer &other)
Assignment operator.
Definition: kserviceoffer.cpp:64
KServiceOffer::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...
Definition: kserviceoffer.cpp:74
KServiceOffer::isValid
bool isValid() const
Check whether the entry is valid.
Definition: kserviceoffer.cpp:114
KServiceOffer::KServiceOffer
KServiceOffer()
Create an invalid service offer.
Definition: kserviceoffer.cpp:39
KServiceOffer::preference
int preference() const
The bigger this number is, the better is this service.
Definition: kserviceoffer.cpp:99
KServiceOffer::service
KService::Ptr service() const
The service which this offer is about.
Definition: kserviceoffer.cpp:109
KSharedPtr< KService >
kserviceoffer.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal