summaryrefslogtreecommitdiffstats
path: root/src/profileengine/lib
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /src/profileengine/lib
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
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
Diffstat (limited to 'src/profileengine/lib')
-rw-r--r--src/profileengine/lib/Mainpage.dox10
-rw-r--r--src/profileengine/lib/Makefile.am16
-rw-r--r--src/profileengine/lib/profile.cpp205
-rw-r--r--src/profileengine/lib/profile.h96
-rw-r--r--src/profileengine/lib/profileengine.cpp264
-rw-r--r--src/profileengine/lib/profileengine.h272
6 files changed, 863 insertions, 0 deletions
diff --git a/src/profileengine/lib/Mainpage.dox b/src/profileengine/lib/Mainpage.dox
new file mode 100644
index 00000000..72d14aa5
--- /dev/null
+++ b/src/profileengine/lib/Mainpage.dox
@@ -0,0 +1,10 @@
+/**
+@mainpage The KDevelop Shell Profiles Library
+
+This library contains plugin profiles engine for KDevelop shell.
+
+<b>Link with</b>: -lprofileengine
+
+<b>Include path</b>: -I\$(kde_includes)/kdevelop/shell/profileengine
+*/
+
diff --git a/src/profileengine/lib/Makefile.am b/src/profileengine/lib/Makefile.am
new file mode 100644
index 00000000..50d17ed5
--- /dev/null
+++ b/src/profileengine/lib/Makefile.am
@@ -0,0 +1,16 @@
+INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/lib/external_interfaces \
+ -I$(top_srcdir)/lib/interfaces -I$(top_srcdir)/lib/util -I$(top_srcdir)/lib/widgets \
+ -I$(top_srcdir)/lib/structure $(all_includes)
+METASOURCES = AUTO
+lib_LTLIBRARIES = libprofileengine.la
+libprofileengine_la_LDFLAGS = $(all_libraries)
+libprofileengine_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_KIO)
+libprofileengine_la_SOURCES = profileengine.cpp profile.cpp
+
+profileincludedir = $(includedir)/kdevelop/shell/profileengine
+profileinclude_HEADERS = profileengine.h profile.h
+
+DOXYGEN_REFERENCES = dcop interfaces kdecore kdefx kdeui khtml kmdi kio kjs kparts kutils kdevutil kdevinterfaces
+DOXYGEN_PROJECTNAME = KDevelop Shell Profiles Library
+DOXYGEN_DOCDIRPREFIX = kdevprofiles
+include ../../../Doxyfile.am
diff --git a/src/profileengine/lib/profile.cpp b/src/profileengine/lib/profile.cpp
new file mode 100644
index 00000000..e13b623e
--- /dev/null
+++ b/src/profileengine/lib/profile.cpp
@@ -0,0 +1,205 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#include "profile.h"
+
+#include <qdir.h>
+#include <qfileinfo.h>
+
+#include <kdebug.h>
+#include <kstandarddirs.h>
+#include <kconfig.h>
+#include <kio/netaccess.h>
+
+Profile::Profile(Profile *parent, const QString &name)
+ :m_parent(parent), m_name(name)
+{
+ if (m_parent)
+ m_parent->addChildProfile(this);
+
+ QString profileConfig = locate("data", "kdevelop/profiles" + dirName() + "/profile.config");
+ KConfig config(profileConfig);
+
+ config.setGroup("Information");
+ m_genericName = config.readEntry("GenericName");
+ m_description = config.readEntry("Description");
+
+ config.setGroup("Properties");
+ m_properties = config.readListEntry("List");
+
+ config.setGroup("Enable");
+ m_explicitEnable = config.readListEntry("List");
+
+ config.setGroup("Disable");
+ m_explicitDisable = config.readListEntry("List");
+}
+
+Profile::Profile(Profile *parent, const QString &name, const QString &genericName, const QString &description)
+ :m_parent(parent), m_name(name), m_genericName(genericName), m_description(description)
+{
+ if (m_parent)
+ m_parent->addChildProfile(this);
+ save();
+}
+
+Profile::~Profile()
+{
+ for (QValueList<Profile*>::iterator it = m_children.begin(); it != m_children.end(); ++it)
+ delete *it;
+}
+
+void Profile::addChildProfile(Profile *profile)
+{
+ m_children.append(profile);
+}
+
+void Profile::removeChildProfile(Profile *profile)
+{
+ m_children.remove(profile);
+}
+
+QString Profile::dirName() const
+{
+ if (m_parent)
+ return m_parent->dirName() + "/" + m_name;
+ else
+ return "/"/* + m_name*/;
+}
+
+void Profile::save()
+{
+ QString profileConfig = locateLocal("data", "kdevelop/profiles" + dirName() + "/profile.config");
+ KConfig config(profileConfig);
+
+ config.setGroup("Information");
+ config.writeEntry("GenericName", m_genericName);
+ config.writeEntry("Description", m_description);
+
+ config.setGroup("Properties");
+ config.writeEntry("List", m_properties);
+
+ config.setGroup("Enable");
+ config.writeEntry("List", m_explicitEnable);
+
+ config.setGroup("Disable");
+ config.writeEntry("List", m_explicitDisable);
+
+ config.sync();
+}
+
+Profile::EntryList Profile::list(List type)
+{
+ EntryList parentList;
+ if (m_parent)
+ parentList = m_parent->list(type);
+ EntryList list = parentList;
+ for (EntryList::iterator it = list.begin(); it != list.end(); ++it)
+ (*it).derived = true;
+ QStringList &personalList = listByType(type);
+ for (QStringList::const_iterator it = personalList.begin(); it != personalList.end(); ++it)
+ list.append(Entry(*it, false));
+ return list;
+}
+
+void Profile::addEntry(List type, const QString &value)
+{
+ QStringList &list = listByType(type);
+ if (!list.contains(value))
+ list.append(value);
+}
+
+void Profile::removeEntry(List type, const QString &value)
+{
+ QStringList &list = listByType(type);
+ list.remove(value);
+}
+
+void Profile::clearList( List type )
+{
+ switch (type)
+ {
+ case Properties:
+ m_properties.clear();
+ case ExplicitEnable:
+ m_explicitEnable.clear();
+ case ExplicitDisable:
+ m_explicitDisable.clear();
+ }
+}
+
+QStringList &Profile::listByType(List type)
+{
+ switch (type) {
+ case Properties:
+ return m_properties;
+ case ExplicitEnable:
+ return m_explicitEnable;
+ case ExplicitDisable:
+ default:
+ return m_explicitDisable;
+ }
+}
+
+bool Profile::hasInEntryList(EntryList &list, QString value)
+{
+ for (EntryList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
+ if ((*it).name == value)
+ return true;
+ return false;
+}
+
+bool Profile::remove()
+{
+ QStringList dirs = KGlobal::dirs()->findDirs("data", "kdevelop/profiles" + dirName());
+ if ((dirs.count() == 1) && dirs[0].startsWith(QDir::homeDirPath()))
+ return KIO::NetAccess::del(KURL::fromPathOrURL(dirs[0]), 0);
+ return false;
+}
+
+void Profile::detachFromParent()
+{
+ if (m_parent)
+ m_parent->removeChildProfile(this);
+}
+
+KURL::List Profile::resources(const QString &nameFilter)
+{
+ QStringList resources;
+ QStringList resourceDirs = KGlobal::dirs()->resourceDirs("data");
+ for (QStringList::const_iterator it = resourceDirs.begin(); it != resourceDirs.end(); ++it)
+ {
+ QString dir = *it;
+ dir = dir + "kdevelop/profiles" + dirName();
+
+ QDir d(dir);
+ const QFileInfoList *infoList = d.entryInfoList(nameFilter, QDir::Files);
+ if (!infoList)
+ continue;
+ for (QFileInfoList::const_iterator infoIt = infoList->constBegin();
+ infoIt != infoList->constEnd(); ++ infoIt)
+ resources.append((*infoIt)->absFilePath());
+ }
+
+ return KURL::List(resources);
+}
+
+void Profile::addResource(const KURL &url)
+{
+ QString saveLocation = KGlobal::dirs()->saveLocation("data", "kdevelop/profiles"+dirName(), true);
+ KIO::NetAccess::file_copy(url, KURL::fromPathOrURL(saveLocation), -1, true);
+}
diff --git a/src/profileengine/lib/profile.h b/src/profileengine/lib/profile.h
new file mode 100644
index 00000000..3f6d495a
--- /dev/null
+++ b/src/profileengine/lib/profile.h
@@ -0,0 +1,96 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
+ * *
+ * 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 PROFILE_H
+#define PROFILE_H
+
+#include <kurl.h>
+#include <qstringlist.h>
+
+/**
+@short KDevelop profile
+
+A class which represents a profile for KDevelop platform stored on disk.
+*/
+class Profile {
+public:
+ /**An entry in the lists that store profile information*/
+ struct Entry {
+ Entry() {}
+ Entry(const QString &_name, bool _derived): name(_name), derived(_derived) {}
+ QString name;
+ bool derived;
+ };
+ typedef QValueList<Entry> EntryList;
+
+ /**Lists which are held by a profile.*/
+ enum List {
+ Properties /**<X-KDevelop-Properties defined for this profile.*/,
+ ExplicitEnable /**<A list of explicitly enabled plugins (names).*/,
+ ExplicitDisable /**<A list of explicitly disabled plugins (names).*/
+ };
+
+ Profile(Profile *parent, const QString &name);
+ Profile(Profile *parent, const QString &name, const QString &genericName, const QString &description);
+ ~Profile();
+
+ QValueList<Profile*> children() const { return m_children; }
+ Profile *parent() const { return m_parent; }
+
+ void save();
+ bool remove();
+
+ QString name() const { return m_name; }
+ QString genericName() const { return m_genericName; }
+ QString description() const { return m_description; }
+
+ EntryList list(List type);
+
+ void addEntry(List type, const QString &value);
+ void removeEntry(List type, const QString &value);
+ void clearList(List type);
+
+ bool hasInEntryList(EntryList &list, QString value);
+
+ KURL::List resources(const QString &nameFilter);
+ void addResource(const KURL &url);
+
+ void detachFromParent();
+
+protected:
+ void addChildProfile(Profile *profile);
+ void removeChildProfile(Profile *profile);
+ QString dirName() const;
+
+ QStringList &listByType(List type);
+
+private:
+ Profile *m_parent;
+ QValueList<Profile*> m_children;
+
+ QString m_name;
+
+ QString m_genericName;
+ QString m_description;
+
+ QStringList m_properties;
+ QStringList m_explicitEnable;
+ QStringList m_explicitDisable;
+};
+
+#endif
diff --git a/src/profileengine/lib/profileengine.cpp b/src/profileengine/lib/profileengine.cpp
new file mode 100644
index 00000000..a46fa766
--- /dev/null
+++ b/src/profileengine/lib/profileengine.cpp
@@ -0,0 +1,264 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo <adymo@kdevelop.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#include "profileengine.h"
+
+#include <qdir.h>
+
+#include <kurl.h>
+#include <kdebug.h>
+#include <kglobal.h>
+#include <kstandarddirs.h>
+
+#include <kdevplugin.h>
+
+ProfileEngine::ProfileEngine()
+{
+ QStringList dirs = KGlobal::dirs()->findDirs("data", "kdevelop/profiles");
+
+ m_rootProfile = new Profile(0, "KDevelop");
+
+ QString currPath = "/";
+ QMap<QString, Profile*> passedPaths;
+
+ for (QStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it)
+ processDir(*it, currPath, passedPaths, m_rootProfile);
+}
+
+ProfileEngine::~ProfileEngine()
+{
+ delete m_rootProfile;
+}
+
+void ProfileEngine::processDir(const QString &dir, const QString &currPath, QMap<QString, Profile*> &passedPaths, Profile *root)
+{
+// kdDebug() << "processDir: " << dir << " " << currPath << endl;
+
+ QDir qDir(dir);
+ QStringList entryList = qDir.entryList(QDir::Dirs);
+ for (QStringList::const_iterator eit = entryList.constBegin(); eit != entryList.constEnd(); ++eit)
+ {
+ if ((*eit != "..") && (*eit != "."))
+ {
+ QString dirName = *eit;
+ Profile *profile = 0;
+ if (passedPaths.contains(currPath + dirName))
+ profile = passedPaths[currPath + dirName];
+ else
+ {
+ profile = new Profile(root, dirName);
+ passedPaths[currPath + dirName] = profile;
+ }
+ processDir(dir + *eit + "/", currPath + dirName, passedPaths, profile);
+ }
+ }
+}
+
+KTrader::OfferList ProfileEngine::offers(const QString &profileName, OfferType offerType)
+{
+ ProfileListing listing;
+ Profile *profile = 0;
+ getProfileWithListing(listing, &profile, profileName);
+
+ if (!profile)
+ return KTrader::OfferList();
+
+ QString constraint = QString::fromLatin1("[X-KDevelop-Version] == %1").arg(KDEVELOP_PLUGIN_VERSION);
+ switch (offerType) {
+ case Global:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Global'");
+ break;
+ case Project:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Project'");
+ break;
+ case Core:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Core'");
+ break;
+ }
+ QString constraint_add = "";
+ Profile::EntryList properties = profile->list(Profile::Properties);
+ int i = 0;
+ for (Profile::EntryList::const_iterator it = properties.begin(); it != properties.end(); ++it)
+ constraint_add += QString::fromLatin1(" %1 '%2' in [X-KDevelop-Properties]").
+ arg((i++)==0?"":"or").arg((*it).name);
+ if (!constraint_add.isEmpty())
+ constraint += " and ( " + constraint_add + " ) ";
+
+//BEGIN debug
+/* kdDebug(9000) << "=============" << endl
+ << " =============" << endl
+ << " ============= Query for Profile:" << endl
+ << " " << constraint << endl << endl << endl;*/
+//END debug
+
+ KTrader::OfferList list = KTrader::self()->query(QString::fromLatin1("KDevelop/Plugin"), constraint);
+ QStringList names;
+
+/* Wrong, this is not what we want to do.
+ Profile::EntryList disableList = profile->list(Profile::ExplicitDisable);
+ KTrader::OfferList::iterator it = list.begin();
+ while (it != list.end())
+ {
+ QString name = (*it)->desktopEntryName();
+ names.append(name);
+ if (profile->hasInEntryList(disableList, name))
+ {
+ it = list.remove(it);
+ continue;
+ }
+ ++it;
+ }
+*/
+ Profile::EntryList enableList = profile->list(Profile::ExplicitEnable);
+ for (Profile::EntryList::const_iterator it = enableList.begin(); it != enableList.end(); ++it)
+ {
+ if (names.contains((*it).name))
+ continue;
+ QString constraint = QString::fromLatin1("[X-KDevelop-Version] == %1").arg(KDEVELOP_PLUGIN_VERSION);
+ constraint += QString::fromLatin1("and [Name] == '%1'").arg((*it).name);
+ KTrader::OfferList enable = KTrader::self()->query(QString::fromLatin1("KDevelop/Plugin"), constraint);
+ list += enable;
+ }
+
+/*//BEGIN debug
+ kdDebug() << "=============" << endl
+ << " =============" << endl
+ << " ============= Plugins for Profile:" << endl;
+ for (KTrader::OfferList::const_iterator it = list.begin(); it != list.end(); ++it)
+ kdDebug() << " " << (*it)->name() << endl;
+ kdDebug() << endl << endl;
+//END debug*/
+
+ return list;
+}
+
+KTrader::OfferList ProfileEngine::allOffers(OfferType offerType)
+{
+ QString constraint = QString::fromLatin1("[X-KDevelop-Version] == %1").arg(KDEVELOP_PLUGIN_VERSION);
+ switch (offerType) {
+ case Global:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Global'");
+ break;
+ case Project:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Project'");
+ break;
+ case Core:
+ constraint += QString::fromLatin1(" and [X-KDevelop-Scope] == 'Core'");
+ break;
+ }
+ return KTrader::self()->query(QString::fromLatin1("KDevelop/Plugin"), constraint);
+}
+
+void ProfileEngine::getProfileWithListing(ProfileListing &listing, Profile **profile,
+ const QString &profileName)
+{
+ if (profileName == "KDevelop")
+ *profile = m_rootProfile;
+ else
+ {
+ walkProfiles<ProfileListing>(listing, m_rootProfile);
+ *profile = listing.profiles[profileName];
+ }
+}
+
+KURL::List ProfileEngine::resources(const QString &profileName, const QString &nameFilter)
+{
+ ProfileListing listing;
+ Profile *profile = 0;
+ getProfileWithListing(listing, &profile, profileName);
+
+ if (!profile)
+ return KURL::List();
+
+ return resources(profile, nameFilter);
+}
+
+KURL::List ProfileEngine::resources(Profile *profile, const QString &nameFilter)
+{
+ return profile->resources(nameFilter);
+}
+
+KURL::List ProfileEngine::resourcesRecursive(const QString &profileName, const QString &nameFilter)
+{
+ ProfileListing listing;
+ Profile *profile = 0;
+ getProfileWithListing(listing, &profile, profileName);
+ KURL::List resources = profile->resources(nameFilter);
+
+ ProfileListingEx listingEx(nameFilter);
+ walkProfiles<ProfileListingEx>(listingEx, profile);
+
+ resources += listingEx.resourceList;
+ return resources;
+}
+
+void ProfileEngine::diffProfiles(OfferType offerType, const QString &profile1,
+ const QString &profile2, QStringList &unload, KTrader::OfferList &load)
+{
+ KTrader::OfferList offers1 = offers(profile1, offerType);
+ KTrader::OfferList offers2 = offers(profile2, offerType);
+
+ QStringList offers1List;
+ for (KTrader::OfferList::const_iterator it = offers1.constBegin();
+ it != offers1.constEnd(); ++it)
+ offers1List.append((*it)->desktopEntryName());
+ QMap<QString, KService::Ptr> offers2List;
+ for (KTrader::OfferList::const_iterator it = offers2.constBegin();
+ it != offers2.constEnd(); ++it)
+ offers2List[(*it)->desktopEntryName()] = *it;
+
+// kdDebug() << "OLD PROFILE: " << offers1List << endl;
+// kdDebug() << "NEW PROFILE: " << offers2List << endl;
+
+ for (QStringList::const_iterator it = offers1List.constBegin();
+ it != offers1List.constEnd(); ++it)
+ {
+// kdDebug() << "checking: " << *it << endl;
+ if (offers2List.contains(*it))
+ {
+// kdDebug() << " keep" << endl;
+ offers2.remove(offers2List[*it]);
+ }
+ else
+ {
+// kdDebug() << " unload" << endl;
+ unload.append(*it);
+ }
+ }
+ load = offers2;
+}
+
+Profile *ProfileEngine::findProfile(const QString & profileName)
+{
+ Profile *profile;
+ ProfileListing listing;
+ getProfileWithListing(listing, &profile, profileName);
+ return profile;
+}
+
+void ProfileEngine::addResource(const QString &profileName, const KURL &url)
+{
+ ProfileListing listing;
+ Profile *profile = 0;
+ getProfileWithListing(listing, &profile, profileName);
+
+ if (!profile)
+ return;
+
+ profile->addResource(url);
+}
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 <adymo@kdevelop.org> *
+ * *
+ * 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 <qmap.h>
+
+#include <ktrader.h>
+
+#include "profile.h"
+
+/**
+Profile listing operation.
+Used to get a plain list of profiles
+and store it in the QMap<QString, Profile*>.
+*/
+class ProfileListing{
+public:
+ void operator() (Profile *profile)
+ {
+ profiles[profile->name()] = profile;
+ }
+
+ QMap<QString, Profile*> 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 /**<Global plugins.*/,
+ Project /**<Project plugins.*/,
+ Core /**<Core plugins.*/
+ };
+
+ /**@return The list of plugin offers for given profile and type.*/
+ KTrader::OfferList offers(const QString &profileName, OfferType offerType);
+ /**@return The list of all plugin offers for given type.*/
+ KTrader::OfferList allOffers(OfferType offerType);
+
+ /**@return The list of URLs to the resources (files) with given @p extension.
+ @param profileName A name of a profile to find resources in.
+ @param nameFilter Name filter for files. @see QDir::setNameFilter documentation
+ for name filters syntax.*/
+ KURL::List resources(const QString &profileName, const QString &nameFilter);
+
+ /**@return The list of URLs to the resources (files) with given @p extension.
+ This list is obtained by a recursive search that process given profile
+ and all it's subprofiles.
+ @param profileName A name of a profile to find resources in.
+ @param nameFilter Name filter for files. @see QDir::setNameFilter documentation
+ for name filters syntax.*/
+ KURL::List resourcesRecursive(const QString &profileName, const QString &nameFilter);
+
+ /**Adds a resource for the profile. Resource will be copied to the user profile directory
+ (like $HOME/.kde/share/apps/kdevelop/profiles/...).
+ @param profileName A name of the profile.
+ @param url The url to a file to copy as a profile resource.*/
+ void addResource(const QString &profileName, const KURL &url);
+
+ /**Gets the difference between @p profile1 and @p profile2.
+ Difference is calculated as two lists of plugins to be unloaded and loaded
+ in order to switch from @p profile1 to @p profile2.
+ @param offerType A type of plugin offers to list.
+ @param profile1 A name of the first profile.
+ @param profile2 A name of the second profile.
+ @param unload Will be filled with a list of plugins to unload.
+ @param load Will be filled with a list of plugins to load.
+ @note Resulting lists are not cleared. Pass only clean lists in the
+ common case.*/
+ void diffProfiles(OfferType offerType, const QString &profile1, const QString &profile2,
+ QStringList &unload, KTrader::OfferList &load);
+
+ /**@return The root profile. Root profile is always named "KDevelop" and it
+ defines an empty list of plugins. Applications built on KDevelop platform
+ will define nested profiles.*/
+ Profile *rootProfile() const { return m_rootProfile; }
+ /**Finds a profile with given name.
+ @return The profile found or 0 if it does not exist.*/
+ Profile *findProfile(const QString &profileName);
+
+ /**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).
+
+ Operation is a class that have operator(Profile *).
+ Example of operation class which is used to build a plain list of profiles:
+ @code
+ class ProfileListing{
+ public:
+ void operator() (Profile *profile)
+ {
+ profiles[profile->name()] = profile;
+ }
+
+ QMap<QString, Profile*> profiles;
+ };
+ @endcode
+ Use case for such operation - building a list of all profiles:
+ @code
+ ProfileEngine engine;
+ ProfileListing listing;
+ engine.walkProfiles<ProfileListing>(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<class Operation>
+ void walkProfiles(Operation &op, Profile *root)
+ {
+ QValueList<Profile*> children = root->children();
+ for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
+ {
+ op(*it);
+ walkProfiles<Operation>(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<ProfileListBuilding, ProfileItem>(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<class Operation, class Result>
+ void walkProfiles(Operation &op, Result *result, Profile *root)
+ {
+ QValueList<Profile*> children = root->children();
+ for (QValueList<Profile*>::iterator it = children.begin(); it != children.end(); ++it)
+ {
+ Result *newResult = op(result, *it);
+ walkProfiles<Operation>(op, newResult, *it);
+ }
+ }
+
+protected:
+ void processDir(const QString &dir, const QString &currPath, QMap<QString, Profile*> &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