1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 1999 Waldo Bastian <bastian@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 as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __kservicetype_h__
22#define __kservicetype_h__
23
24#include <ksycocaentry.h>
25
26#include <QtCore/QString>
27#include <QtCore/QStringList>
28#include <QtCore/QMap>
29#include <QtCore/QVariant>
30
31#include <kconfig.h>
32
33class KDesktopFile;
34class KServiceTypePrivate;
35
36/**
37 * A service type is, well, a type of service, where a service is an application or plugin.
38 * For instance, "KOfficeFilter", which is the type of all koffice filters, is a service type.
39 * In order to discover services of a given type, using KServiceTypeTrader.
40 * Service types are stored as desktop files in $KDEDIR/share/servicetypes.
41 * @see KService, KServiceTypeTrader
42 */
43class KDECORE_EXPORT KServiceType : public KSycocaEntry // TODO KDE5: inherit kshared, but move KSycocaEntry to Private
44{
45public:
46 typedef KSharedPtr<KServiceType> Ptr;
47 typedef QList<Ptr> List;
48
49 /**
50 * Construct a service type and take all information from a desktop file.
51 * @param config the configuration file
52 */
53 explicit KServiceType( KDesktopFile *config );
54
55 /**
56 * @internal construct a service from a stream.
57 * The stream must already be positionned at the correct offset
58 */
59 KServiceType( QDataStream& _str, int offset );
60
61 virtual ~KServiceType();
62
63 /**
64 * Returns the descriptive comment associated, if any.
65 * @return the comment, or QString()
66 */
67 QString comment() const;
68
69 /**
70 * Returns the relative path to the desktop entry file responsible for
71 * this servicetype.
72 * For instance inode/directory.desktop, or kpart.desktop
73 * @return the path of the desktop file
74 */
75#ifndef KDE_NO_DEPRECATED
76 KDE_DEPRECATED QString desktopEntryPath() const;
77#endif
78
79 /**
80 * Checks whether this service type inherits another one.
81 * @return true if this service type inherits another one
82 * @see parentServiceType()
83 */
84 bool isDerived() const;
85
86 /**
87 * If this service type inherits from another service type,
88 * return the name of the parent.
89 * @return the parent service type, or QString:: null if not set
90 * @see isDerived()
91 */
92 QString parentServiceType() const;
93
94 /**
95 * Checks whether this service type is or inherits from @p servTypeName.
96 * @return true if this servicetype is or inherits from @p servTypeName
97 */
98 bool inherits( const QString& servTypeName ) const;
99
100 /**
101 * Returns the type of the property definition with the given @p _name.
102 *
103 * @param _name the name of the property
104 * @return the property type, or null if not found
105 * @see propertyDefNames
106 */
107 QVariant::Type propertyDef( const QString& _name ) const;
108
109 /**
110 * Returns the list of all property definitions for this servicetype.
111 * Those are properties of the services implementing this servicetype.
112 * For instance,
113 * @code
114 * [PropertyDef::X-KDevelop-Version]
115 * Type=int
116 * @endcode
117 * means that all kdevelop plugins have in their .desktop file a line like
118 * @code
119 * X-KDevelop-Version=<some value>
120 * @endcode
121 */
122 QStringList propertyDefNames() const;
123
124 /// @internal (for KBuildServiceTypeFactory)
125 QMap<QString,QVariant::Type> propertyDefs() const;
126
127 /**
128 * @internal
129 * Pointer to parent service type
130 */
131 Ptr parentType();
132 /**
133 * @internal only used by kbuildsycoca
134 * Register offset into offers list
135 */
136 void setServiceOffersOffset( int offset );
137 /**
138 * @internal
139 */
140 int serviceOffersOffset() const;
141
142 /**
143 * Returns a pointer to the servicetype '_name' or 0L if the
144 * service type is unknown.
145 * VERY IMPORTANT : don't store the result in a KServiceType * !
146 * @param _name the name of the service type to search
147 * @return the pointer to the service type, or 0
148 */
149 static Ptr serviceType( const QString& _name );
150
151 /**
152 * Returns a list of all the supported servicetypes. Useful for
153 * showing the list of available servicetypes in a listbox,
154 * for example.
155 * More memory consuming than the ones above, don't use unless
156 * really necessary.
157 * @return the list of all services
158 */
159 static List allServiceTypes();
160
161protected: // used by KMimeType
162
163 /**
164 * Construct a servicetype from another servicetype's private object
165 *
166 * @param dd the private object
167 */
168 KServiceType( KServiceTypePrivate &dd);
169
170 /**
171 * Construct a servicetype based on another servicetype's private object
172 *
173 * Allows the name and comment to be overridden.
174 *
175 * @param dd the private object
176 * @param _name the name of the service type
177 * @param _comment a comment (can be empty)
178 */
179 KServiceType( KServiceTypePrivate &dd, const QString& _name,
180 const QString& _comment );
181
182private:
183 Q_DECLARE_PRIVATE(KServiceType)
184};
185
186//QDataStream& operator>>( QDataStream& _str, KServiceType& s );
187//QDataStream& operator<<( QDataStream& _str, KServiceType& s );
188
189#endif
190