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

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • 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 
22 class KServiceOffer::Private
23 {
24 public:
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 
39 KServiceOffer::KServiceOffer()
40  : d( new Private )
41 {
42 }
43 
44 KServiceOffer::KServiceOffer( const KServiceOffer& _o )
45  : d( new Private )
46 {
47  *d = *_o.d;
48 }
49 
50 KServiceOffer::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 
59 KServiceOffer::~KServiceOffer()
60 {
61  delete d;
62 }
63 
64 KServiceOffer& KServiceOffer::operator=( const KServiceOffer& rhs )
65 {
66  if ( this == &rhs ) {
67  return *this;
68  }
69 
70  *d = *rhs.d;
71  return *this;
72 }
73 
74 bool 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 
94 bool KServiceOffer::allowAsDefault() const
95 {
96  return d->bAllowAsDefault;
97 }
98 
99 int KServiceOffer::preference() const
100 {
101  return d->preference;
102 }
103 
104 void KServiceOffer::setPreference( int p )
105 {
106  d->preference = p;
107 }
108 
109 KService::Ptr KServiceOffer::service() const
110 {
111  return d->pService;
112 }
113 
114 bool KServiceOffer::isValid() const
115 {
116  return d->preference >= 0;
117 }
118 
119 void KServiceOffer::setMimeTypeInheritanceLevel(int level)
120 {
121  d->mimeTypeInheritanceLevel = level;
122 }
123 
124 int KServiceOffer::mimeTypeInheritanceLevel() const
125 {
126  return d->mimeTypeInheritanceLevel;
127 }
128 
KSharedPtr
Can be used to control the lifetime of an object that has derived QSharedData.
Definition: kconfiggroup.h:38
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.h
KServiceOffer::service
KService::Ptr service() const
The service which this offer is about.
Definition: kserviceoffer.cpp:109
KServiceOffer::~KServiceOffer
~KServiceOffer()
Definition: kserviceoffer.cpp:59
KServiceOffer::KServiceOffer
KServiceOffer()
Create an invalid service offer.
Definition: kserviceoffer.cpp:39
KServiceOffer
Holds the user's preference of a service.
Definition: kserviceoffer.h:38
KServiceOffer::preference
int preference() const
The bigger this number is, the better is this service.
Definition: kserviceoffer.cpp:99
KServiceOffer::isValid
bool isValid() const
Check whether the entry is valid.
Definition: kserviceoffer.cpp:114
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::allowAsDefault
bool allowAsDefault() const
Is it allowed to use this service for default actions (e.g.
Definition: kserviceoffer.cpp:94
KServiceOffer::mimeTypeInheritanceLevel
int mimeTypeInheritanceLevel() const
Mimetype inheritance level.
Definition: kserviceoffer.cpp:124
KServiceOffer::setPreference
void setPreference(int p)
The bigger this number is, the better is this service.
Definition: kserviceoffer.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:09 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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