Warning: That file was not part of the compilation database. It may have many parsing errors.

1/* This file is part of the KDE project
2 Copyright (C) 2000 Waldo Bastian <bastian@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17*/
18
19#ifndef KSERVICEGROUP_H
20#define KSERVICEGROUP_H
21
22#include <kdecore_export.h>
23#include <ksycocaentry.h>
24#include <kservice.h>
25
26class KBuildServiceGroupFactory;
27
28class KServiceGroupPrivate;
29
30/**
31 * KServiceGroup represents a group of service, for example
32 * screensavers.
33 * This class is typically used like this:
34 *
35 * \code
36 * // Start from root group
37 * KServiceGroup::Ptr group = KServiceGroup::root();
38 * if (!group || !group->isValid()) return;
39 *
40 * KServiceGroup::List list = group->entries();
41 *
42 * // Iterate over all entries in the group
43 * for( KServiceGroup::List::ConstIterator it = list.begin();
44 * it != list.end(); it++)
45 * {
46 * KSycocaEntry *p = (*it);
47 * if (p->isType(KST_KService))
48 * {
49 * KService *s = static_cast<KService *>(p);
50 * printf("Name = %s\n", s->name().toLatin1());
51 * }
52 * else if (p->isType(KST_KServiceGroup))
53 * {
54 * KServiceGroup *g = static_cast<KServiceGroup *>(p);
55 * // Sub group ...
56 * }
57 * }
58 * \endcode
59 *
60 * @short Represents a group of services
61 */
62class KDECORE_EXPORT KServiceGroup : public KSycocaEntry
63{
64 friend class KBuildServiceGroupFactory;
65public:
66 typedef KSharedPtr<KServiceGroup> Ptr;
67 typedef KSharedPtr<KSycocaEntry> SPtr;
68 typedef QList<SPtr> List;
69public:
70 /**
71 * Construct a dummy servicegroup indexed with @p name.
72 * @param name the name of the service group
73 */
74 KServiceGroup( const QString & name );
75
76 /**
77 * Construct a service and take all information from a config file
78 * @param _fullpath full path to the config file
79 * @param _relpath relative path to the config file
80 */
81 KServiceGroup( const QString & _fullpath, const QString & _relpath );
82
83 /**
84 * @internal construct a service from a stream.
85 * The stream must already be positionned at the correct offset
86 */
87 KServiceGroup( QDataStream& _str, int offset, bool deep );
88
89 virtual ~KServiceGroup();
90
91 /**
92 * Returns the relative path of the service group.
93 * @return the service group's relative path
94 */
95 QString relPath() const;
96
97 /**
98 * Returns the caption of this group.
99 * @return the caption of this group
100 */
101 QString caption() const;
102
103 /**
104 * Returns the name of the icon associated with the group.
105 * @return the name of the icon associated with the group,
106 * or QString() if not set
107 */
108 QString icon() const;
109
110 /**
111 * Returns the comment about this service group.
112 * @return the descriptive comment for the group, if there is one,
113 * or QString() if not set
114 */
115 QString comment() const;
116
117 /**
118 * Returns the total number of displayable services in this group and
119 * any of its subgroups.
120 * @return the number of child services
121 */
122 int childCount() const;
123
124 /**
125 * Returns true if the NoDisplay flag was set, i.e. if this
126 * group should be hidden from menus, while still being in ksycoca.
127 * @return true to hide this service group, false to display it
128 */
129 bool noDisplay() const;
130
131 /**
132 * Return true if we want to display empty menu entry
133 * @return true to show this service group as menu entry is empty, false to hide it
134 */
135 bool showEmptyMenu() const;
136 void setShowEmptyMenu( bool b);
137
138 /**
139 * @return true to show an inline header into menu
140 */
141 bool showInlineHeader() const;
142 void setShowInlineHeader(bool _b);
143
144 /**
145 * @return true to show an inline alias item into menu
146 */
147 bool inlineAlias() const;
148 void setInlineAlias(bool _b);
149 /**
150 * @return true if we allow to inline menu.
151 */
152 bool allowInline() const;
153 void setAllowInline(bool _b);
154
155 /**
156 * @return inline limite value
157 */
158 int inlineValue() const;
159 void setInlineValue(int _val);
160
161
162 /**
163 * Returns a list of untranslated generic names that should be
164 * be suppressed when showing this group.
165 * E.g. The group "Games/Arcade" might want to suppress the generic name
166 * "Arcade Game" since it's redundant in this particular context.
167 */
168 QStringList suppressGenericNames() const;
169
170 /**
171 * @internal
172 * Sets information related to the layout of services in this group.
173 */
174 void setLayoutInfo(const QStringList &layout);
175
176 /**
177 * @internal
178 * Returns information related to the layout of services in this group.
179 */
180 QStringList layoutInfo() const;
181
182 /**
183 * List of all Services and ServiceGroups within this
184 * ServiceGroup.
185 * @param sorted true to sort items
186 * @param excludeNoDisplay true to exclude items marked "NoDisplay"
187 * @param allowSeparators true to allow separator items to be included
188 * @param sortByGenericName true to sort GenericName+Name instead of Name+GenericName
189 * @return the list of entries
190 */
191 List entries(bool sorted, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName=false);
192 List entries(bool sorted, bool excludeNoDisplay);
193
194 /**
195 * List of all Services and ServiceGroups within this
196 * ServiceGroup.
197 * @param sorted true to sort items
198 * @return the list of entried
199 */
200 List entries(bool sorted = false);
201
202 /**
203 * options for groupEntries and serviceEntries
204 */
205 enum EntriesOption
206 {
207 NoOptions = 0x0,
208 SortEntries = 0x1, /*< sort items */
209 ExcludeNoDisplay = 0x2, /*< exclude items marked "NoDisplay" */
210 AllowSeparators = 0x4, /*< allow separator items to be included */
211 SortByGenericName = 0x8 /*< sort by GenericName+Name instead of Name+GenericName */
212 };
213 Q_DECLARE_FLAGS(EntriesOptions, EntriesOption)
214
215 /**
216 * subgroups for this service group
217 */
218 QList<Ptr> groupEntries(EntriesOptions options = ExcludeNoDisplay);
219
220 /**
221 * entries of this service group
222 */
223 KService::List serviceEntries(EntriesOptions options = ExcludeNoDisplay);
224
225 /**
226 * Returns a non-empty string if the group is a special base group.
227 * By default, "Settings/" is the kcontrol base group ("settings")
228 * and "System/Screensavers/" is the screensavers base group ("screensavers").
229 * This allows moving the groups without breaking those apps.
230 *
231 * The base group is defined by the X-KDE-BaseGroup key
232 * in the .directory file.
233 * @return the base group name, or null if no base group
234 */
235 QString baseGroupName() const;
236
237 /**
238 * Returns a path to the .directory file describing this service group.
239 * The path is either absolute or relative to the "apps" resource.
240 */
241 QString directoryEntryPath() const;
242
243 /**
244 * Returns the group for the given baseGroupName.
245 * Can return 0L if the directory (or the .directory file) was deleted.
246 * @return the base group with the given name, or 0 if not available.
247 *
248 * This mechanism was fragile and isn't used in kde4 anymore.
249 * @deprecated Use a servicetype and a proper trader query instead, for a better
250 * way of finding related services.
251 */
252#ifndef KDE_NO_DEPRECATED
253 static KDE_DEPRECATED Ptr baseGroup( const QString &baseGroupName );
254#endif
255
256 /**
257 * Returns the root service group.
258 * @return the root service group
259 */
260 static Ptr root();
261
262 /**
263 * Returns the group with the given relative path.
264 * @param relPath the path of the service group
265 * @return the group with the given relative path name.
266 */
267 static Ptr group(const QString &relPath);
268
269 /**
270 * Returns the group of services that have X-KDE-ParentApp equal
271 * to @p parent (siblings).
272 * @param parent the name of the service's parent
273 * @return the services group
274 */
275 static Ptr childGroup(const QString &parent);
276
277protected:
278 /**
279 * @internal
280 * Add a service to this group
281 */
282 void addEntry( const KSycocaEntry::Ptr& entry);
283private:
284 Q_DECLARE_PRIVATE(KServiceGroup)
285};
286
287#endif
288

Warning: That file was not part of the compilation database. It may have many parsing errors.