From 114a878c64ce6f8223cfd22d76a20eb16d177e5e Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/profileengine/lib/profileengine.h | 272 ++++++++++++++++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 src/profileengine/lib/profileengine.h (limited to 'src/profileengine/lib/profileengine.h') diff --git a/src/profileengine/lib/profileengine.h b/src/profileengine/lib/profileengine.h new file mode 100644 index 00000000..7a9a9abf --- /dev/null +++ b/src/profileengine/lib/profileengine.h @@ -0,0 +1,272 @@ +/*************************************************************************** + * Copyright (C) 2004 by Alexander Dymo * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU Library General Public License as * + * published by the Free Software Foundation; either version 2 of the * + * License, or (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef PROFILEENGINE_H +#define PROFILEENGINE_H + +#include + +#include + +#include "profile.h" + +/** +Profile listing operation. +Used to get a plain list of profiles +and store it in the QMap. +*/ +class ProfileListing{ +public: + void operator() (Profile *profile) + { + profiles[profile->name()] = profile; + } + + QMap profiles; +}; + +/**Profile resource listing operation. +Used to get a list of urls to the profile resources. + +Resource urls can be filtered by an @p filter parameter +passed to the constructor. Filter can have values +as described in @ref QDir::setNameFilter function documentation.*/ +class ProfileListingEx { +public: + ProfileListingEx(const QString &filter): m_filter(filter) {} + void operator() (Profile *profile) + { + resourceList += profile->resources(m_filter); + } + + KURL::List resourceList; + QString m_filter; +}; + +/** +Profile engine. + +- Uses KDevelop profiles to form lists of plugin offers; +- Provides means of managing profiles; +- Provides means to access the resources provided by a profile. + +KDevelop profiles form a tree with a root profile named "KDevelop". +For example, such profiles tree can look as: +@code +KDevelop +- IDE + - CompiledLanguageIDE + - AdaIDE + - CandCppIDE + - CIDE + - CppIDE + - KDECppIDE + - FortranIDE + ... + - DatabaseIDE + - ScriptingLanguageIDE + .. +- KDevAssistant +@endcode +To manage a tree of profiles, use @ref ProfileEngine::walkProfiles methods. +*/ +class ProfileEngine { +public: + ProfileEngine(); + ~ProfileEngine(); + + /**Type of the plugin offer. Engine will usually find profiles and return offers + of selected type. + @sa KDevPlugin class documentation for more information of plugin types.*/ + enum OfferType { + Global /**name()] = profile; + } + + QMap profiles; + }; + @endcode + Use case for such operation - building a list of all profiles: + @code + ProfileEngine engine; + ProfileListing listing; + engine.walkProfiles(listing, engine.rootProfile()); + @endcode + + @note @ref ProfileListing and @ref ProfileListingEx operations are already defined in + profileengine.h header file. + + @param op An operation to apply. + @param root A profile to start walking from. Complete subtree of the @p root is traversed. + */ + template + void walkProfiles(Operation &op, Profile *root) + { + QValueList children = root->children(); + for (QValueList::iterator it = children.begin(); it != children.end(); ++it) + { + op(*it); + walkProfiles(op, *it); + } + } + /**Walks profiles tree and applies operation @p op to each profile + found in the tree below @p root (@p root profile itself is not processed) + but the operation in this case returns a result of type defined by + "Result" template parameter. + + When iterating the tree, the result of operation applied to the parent profile + is passed as @p result parameter to the recursive call for child profiles. + + For example, this function can be used to build another hierarcy of profiles + or other objects connected to profiles. + Example of operation class which is used to build a listview with items + where each item represents a profile: + @code + class ProfileListBuilding { + public: + ProfileItem * operator() (ProfileItem *parent, Profile *profile) + { + parent->setOpen(true); + return new ProfileItem(parent, profile); + } + }; + + class ProfileItem: public KListViewItem { + public: + ProfileItem(KListView *parent, Profile *profile) + :KListViewItem(parent), m_profile(profile) + { + setText(0, profile->genericName()); + setText(1, profile->description()); + } + + ProfileItem(KListViewItem *parent, Profile *profile) + : KListViewItem(parent), m_profile(profile) + { + setText(0, profile->genericName()); + setText(1, profile->description()); + } + + Profile *profile() const { return m_profile; } + + private: + Profile *m_profile; + }; + + @endcode + Use case for such operation - building a listview: + @code + ProfileEngine engine; + ProfileItem *item = new ProfileItem(profilesList, engine.rootProfile()); + ProfileListBuilding op; + engine.walkProfiles(op, item, engine.rootProfile()); + @endcode + + @param op An operation to apply. + @param result A result of the operation as it would have been applied to the @p root. + @param root A profile to start walking from. Complete subtree of the @p root is traversed. + */ + template + void walkProfiles(Operation &op, Result *result, Profile *root) + { + QValueList children = root->children(); + for (QValueList::iterator it = children.begin(); it != children.end(); ++it) + { + Result *newResult = op(result, *it); + walkProfiles(op, newResult, *it); + } + } + +protected: + void processDir(const QString &dir, const QString &currPath, QMap &passedPaths, Profile *root); + + KURL::List resources(Profile *profile, const QString &nameFilter); + + /**Gets a complete listing of available profiles and looks for a profile. + @param listing Profiles listing will be saved here. + @param profile Will be a pointer to a profile with the name @p profileName or 0 + if no profile with that name is found. + @param profileName The name of a profile to find.*/ + void getProfileWithListing(ProfileListing &listing, Profile **profile, + const QString &profileName); + +private: + Profile *m_rootProfile; +}; + +#endif -- cgit v1.2.3