1
/***************************************************************************
2
* Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
4
* This program is free software; you can redistribute it and/or modify *
5
* it under the terms of the GNU Library General Public License as *
6
* published by the Free Software Foundation; either version 2 of the *
7
* License, or (at your option) any later version. *
9
* This program 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 *
12
* GNU General Public License for more details. *
14
* You should have received a copy of the GNU Library General Public *
15
* License along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef PROFILEENGINE_H
20
#define PROFILEENGINE_H
29
Profile listing operation.
30
Used to get a plain list of profiles
31
and store it in the QMap<QString, Profile*>.
35
void operator() (Profile *profile)
37
profiles[profile->name()] = profile;
40
QMap<QString, Profile*> profiles;
43
/**Profile resource listing operation.
44
Used to get a list of urls to the profile resources.
46
Resource urls can be filtered by an @p filter parameter
47
passed to the constructor. Filter can have values
48
as described in @ref QDir::setNameFilter function documentation.*/
49
class ProfileListingEx {
51
ProfileListingEx(const QString &filter): m_filter(filter) {}
52
void operator() (Profile *profile)
54
resourceList += profile->resources(m_filter);
57
KURL::List resourceList;
64
- Uses KDevelop profiles to form lists of plugin offers;
65
- Provides means of managing profiles;
66
- Provides means to access the resources provided by a profile.
68
KDevelop profiles form a tree with a root profile named "KDevelop".
69
For example, such profiles tree can look as:
82
- ScriptingLanguageIDE
86
To manage a tree of profiles, use @ref ProfileEngine::walkProfiles methods.
93
/**Type of the plugin offer. Engine will usually find profiles and return offers
95
@sa KDevPlugin class documentation for more information of plugin types.*/
97
Global /**<Global plugins.*/,
98
Project /**<Project plugins.*/,
99
Core /**<Core plugins.*/
102
/**@return The list of plugin offers for given profile and type.*/
103
KTrader::OfferList offers(const QString &profileName, OfferType offerType);
104
/**@return The list of all plugin offers for given type.*/
105
KTrader::OfferList allOffers(OfferType offerType);
107
/**@return The list of URLs to the resources (files) with given @p extension.
108
@param profileName A name of a profile to find resources in.
109
@param nameFilter Name filter for files. @see QDir::setNameFilter documentation
110
for name filters syntax.*/
111
KURL::List resources(const QString &profileName, const QString &nameFilter);
113
/**@return The list of URLs to the resources (files) with given @p extension.
114
This list is obtained by a recursive search that process given profile
115
and all it's subprofiles.
116
@param profileName A name of a profile to find resources in.
117
@param nameFilter Name filter for files. @see QDir::setNameFilter documentation
118
for name filters syntax.*/
119
KURL::List resourcesRecursive(const QString &profileName, const QString &nameFilter);
121
/**Adds a resource for the profile. Resource will be copied to the user profile directory
122
(like $HOME/.kde/share/apps/kdevelop/profiles/...).
123
@param profileName A name of the profile.
124
@param url The url to a file to copy as a profile resource.*/
125
void addResource(const QString &profileName, const KURL &url);
127
/**Gets the difference between @p profile1 and @p profile2.
128
Difference is calculated as two lists of plugins to be unloaded and loaded
129
in order to switch from @p profile1 to @p profile2.
130
@param offerType A type of plugin offers to list.
131
@param profile1 A name of the first profile.
132
@param profile2 A name of the second profile.
133
@param unload Will be filled with a list of plugins to unload.
134
@param load Will be filled with a list of plugins to load.
135
@note Resulting lists are not cleared. Pass only clean lists in the
137
void diffProfiles(OfferType offerType, const QString &profile1, const QString &profile2,
138
QStringList &unload, KTrader::OfferList &load);
140
/**@return The root profile. Root profile is always named "KDevelop" and it
141
defines an empty list of plugins. Applications built on KDevelop platform
142
will define nested profiles.*/
143
Profile *rootProfile() const { return m_rootProfile; }
144
/**Finds a profile with given name.
145
@return The profile found or 0 if it does not exist.*/
146
Profile *findProfile(const QString &profileName);
148
/**Walks profiles tree and applies operation @p op to each profile found
149
in the tree below @p root (@p root profile itself is not processed).
151
Operation is a class that have operator(Profile *).
152
Example of operation class which is used to build a plain list of profiles:
154
class ProfileListing{
156
void operator() (Profile *profile)
158
profiles[profile->name()] = profile;
161
QMap<QString, Profile*> profiles;
164
Use case for such operation - building a list of all profiles:
166
ProfileEngine engine;
167
ProfileListing listing;
168
engine.walkProfiles<ProfileListing>(listing, engine.rootProfile());
171
@note @ref ProfileListing and @ref ProfileListingEx operations are already defined in
172
profileengine.h header file.
174
@param op An operation to apply.
175
@param root A profile to start walking from. Complete subtree of the @p root is traversed.
177
template<class Operation>
178
void walkProfiles(Operation &op, Profile *root)
180
QValueList<Profile*> children = root->children();
181
for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
184
walkProfiles<Operation>(op, *it);
187
/**Walks profiles tree and applies operation @p op to each profile
188
found in the tree below @p root (@p root profile itself is not processed)
189
but the operation in this case returns a result of type defined by
190
"Result" template parameter.
192
When iterating the tree, the result of operation applied to the parent profile
193
is passed as @p result parameter to the recursive call for child profiles.
195
For example, this function can be used to build another hierarcy of profiles
196
or other objects connected to profiles.
197
Example of operation class which is used to build a listview with items
198
where each item represents a profile:
200
class ProfileListBuilding {
202
ProfileItem * operator() (ProfileItem *parent, Profile *profile)
204
parent->setOpen(true);
205
return new ProfileItem(parent, profile);
209
class ProfileItem: public KListViewItem {
211
ProfileItem(KListView *parent, Profile *profile)
212
:KListViewItem(parent), m_profile(profile)
214
setText(0, profile->genericName());
215
setText(1, profile->description());
218
ProfileItem(KListViewItem *parent, Profile *profile)
219
: KListViewItem(parent), m_profile(profile)
221
setText(0, profile->genericName());
222
setText(1, profile->description());
225
Profile *profile() const { return m_profile; }
232
Use case for such operation - building a listview:
234
ProfileEngine engine;
235
ProfileItem *item = new ProfileItem(profilesList, engine.rootProfile());
236
ProfileListBuilding op;
237
engine.walkProfiles<ProfileListBuilding, ProfileItem>(op, item, engine.rootProfile());
240
@param op An operation to apply.
241
@param result A result of the operation as it would have been applied to the @p root.
242
@param root A profile to start walking from. Complete subtree of the @p root is traversed.
244
template<class Operation, class Result>
245
void walkProfiles(Operation &op, Result *result, Profile *root)
247
QValueList<Profile*> children = root->children();
248
for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
250
Result *newResult = op(result, *it);
251
walkProfiles<Operation>(op, newResult, *it);
256
void processDir(const QString &dir, const QString &currPath, QMap<QString, Profile*> &passedPaths, Profile *root);
258
KURL::List resources(Profile *profile, const QString &nameFilter);
260
/**Gets a complete listing of available profiles and looks for a profile.
261
@param listing Profiles listing will be saved here.
262
@param profile Will be a pointer to a profile with the name @p profileName or 0
263
if no profile with that name is found.
264
@param profileName The name of a profile to find.*/
265
void getProfileWithListing(ProfileListing &listing, Profile **profile,
266
const QString &profileName);
269
Profile *m_rootProfile;