~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to src/profileengine/lib/profileengine.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org>             *
 
3
 *                                                                         *
 
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.                       *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 
21
 
 
22
#include <qmap.h>
 
23
 
 
24
#include <ktrader.h>
 
25
 
 
26
#include "profile.h"
 
27
 
 
28
/**
 
29
Profile listing operation.
 
30
Used to get a plain list of profiles
 
31
and store it in the QMap<QString, Profile*>.
 
32
*/
 
33
class ProfileListing{
 
34
public:
 
35
    void operator() (Profile *profile)
 
36
    {
 
37
        profiles[profile->name()] = profile;
 
38
    }
 
39
 
 
40
    QMap<QString, Profile*> profiles;
 
41
};
 
42
 
 
43
/**Profile resource listing operation.
 
44
Used to get a list of urls to the profile resources.
 
45
 
 
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 {
 
50
public:
 
51
    ProfileListingEx(const QString &filter): m_filter(filter) {}
 
52
    void operator() (Profile *profile)
 
53
    {
 
54
        resourceList += profile->resources(m_filter);
 
55
    }
 
56
    
 
57
    KURL::List resourceList;
 
58
    QString m_filter;
 
59
};
 
60
 
 
61
/**
 
62
Profile engine.
 
63
 
 
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.
 
67
 
 
68
KDevelop profiles form a tree with a root profile named "KDevelop".
 
69
For example, such profiles tree can look as:
 
70
@code
 
71
KDevelop
 
72
- IDE
 
73
  - CompiledLanguageIDE
 
74
    - AdaIDE
 
75
    - CandCppIDE
 
76
      - CIDE
 
77
      - CppIDE
 
78
        - KDECppIDE
 
79
    - FortranIDE
 
80
    ...
 
81
  - DatabaseIDE
 
82
  - ScriptingLanguageIDE
 
83
  ..
 
84
- KDevAssistant
 
85
@endcode
 
86
To manage a tree of profiles, use @ref ProfileEngine::walkProfiles methods.
 
87
*/
 
88
class ProfileEngine {
 
89
public:
 
90
    ProfileEngine();
 
91
    ~ProfileEngine();
 
92
 
 
93
    /**Type of the plugin offer. Engine will usually find profiles and return offers
 
94
    of selected type.
 
95
    @sa KDevPlugin class documentation for more information of plugin types.*/
 
96
    enum OfferType { 
 
97
        Global    /**<Global plugins.*/,
 
98
        Project   /**<Project plugins.*/,
 
99
        Core      /**<Core plugins.*/
 
100
    };
 
101
    
 
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);
 
106
    
 
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);
 
112
    
 
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);
 
120
    
 
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);
 
126
    
 
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
 
136
    common case.*/
 
137
    void diffProfiles(OfferType offerType, const QString &profile1, const QString &profile2, 
 
138
        QStringList &unload, KTrader::OfferList &load);
 
139
 
 
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);
 
147
    
 
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).
 
150
    
 
151
    Operation is a class that have operator(Profile *).
 
152
    Example of operation class which is used to build a plain list of profiles:
 
153
    @code
 
154
    class ProfileListing{
 
155
    public:
 
156
        void operator() (Profile *profile)
 
157
        {
 
158
            profiles[profile->name()] = profile;
 
159
        }
 
160
    
 
161
        QMap<QString, Profile*> profiles;
 
162
    };
 
163
    @endcode
 
164
    Use case for such operation - building a list of all profiles:
 
165
    @code
 
166
    ProfileEngine engine;
 
167
    ProfileListing listing;
 
168
    engine.walkProfiles<ProfileListing>(listing, engine.rootProfile());
 
169
    @endcode
 
170
    
 
171
    @note @ref ProfileListing and @ref ProfileListingEx operations are already defined in 
 
172
    profileengine.h header file.
 
173
    
 
174
    @param op An operation to apply.
 
175
    @param root A profile to start walking from. Complete subtree of the @p root is traversed.
 
176
    */
 
177
    template<class Operation>
 
178
    void walkProfiles(Operation &op, Profile *root)
 
179
    {
 
180
        QValueList<Profile*> children = root->children();
 
181
        for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
 
182
        {
 
183
            op(*it);
 
184
            walkProfiles<Operation>(op, *it);
 
185
        }
 
186
    }
 
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.
 
191
    
 
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.
 
194
    
 
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:
 
199
    @code
 
200
    class ProfileListBuilding {
 
201
    public:
 
202
        ProfileItem * operator() (ProfileItem *parent, Profile *profile)
 
203
        {
 
204
            parent->setOpen(true);
 
205
            return new ProfileItem(parent, profile);
 
206
        }
 
207
    };
 
208
    
 
209
    class ProfileItem: public KListViewItem {
 
210
    public:
 
211
        ProfileItem(KListView *parent, Profile *profile)
 
212
            :KListViewItem(parent), m_profile(profile)
 
213
        {
 
214
            setText(0, profile->genericName());
 
215
            setText(1, profile->description());
 
216
        }
 
217
        
 
218
        ProfileItem(KListViewItem *parent, Profile *profile)
 
219
            : KListViewItem(parent), m_profile(profile)
 
220
        {
 
221
            setText(0, profile->genericName());
 
222
            setText(1, profile->description());
 
223
        }
 
224
        
 
225
        Profile *profile() const { return m_profile; }
 
226
        
 
227
    private:
 
228
        Profile *m_profile;
 
229
    };
 
230
 
 
231
    @endcode
 
232
    Use case for such operation - building a listview:
 
233
    @code
 
234
    ProfileEngine engine;
 
235
    ProfileItem *item = new ProfileItem(profilesList, engine.rootProfile());
 
236
    ProfileListBuilding op;
 
237
    engine.walkProfiles<ProfileListBuilding, ProfileItem>(op, item, engine.rootProfile());
 
238
    @endcode
 
239
    
 
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.
 
243
    */
 
244
    template<class Operation, class Result>
 
245
    void walkProfiles(Operation &op, Result *result, Profile *root)
 
246
    {
 
247
        QValueList<Profile*> children = root->children();
 
248
        for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
 
249
        {
 
250
            Result *newResult = op(result, *it);
 
251
            walkProfiles<Operation>(op, newResult, *it);
 
252
        }
 
253
    }
 
254
 
 
255
protected:
 
256
    void processDir(const QString &dir, const QString &currPath, QMap<QString, Profile*> &passedPaths, Profile *root);
 
257
 
 
258
    KURL::List resources(Profile *profile, const QString &nameFilter);
 
259
    
 
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);
 
267
    
 
268
private:
 
269
    Profile *m_rootProfile;
 
270
};
 
271
 
 
272
#endif