• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • KDevelop Shell Profiles Library
 

KDevelop Shell Profiles Library

  • src
  • profileengine
  • lib
profileengine.cpp
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
19#include "profileengine.h"
20
21#include <tqdir.h>
22
23#include <kurl.h>
24#include <kdebug.h>
25#include <tdeglobal.h>
26#include <kstandarddirs.h>
27
28#include <kdevplugin.h>
29
30ProfileEngine::ProfileEngine()
31{
32 TQStringList dirs = TDEGlobal::dirs()->findDirs("data", "tdevelop/profiles");
33
34 m_rootProfile = new Profile(0, "KDevelop");
35
36 TQString currPath = "/";
37 TQMap<TQString, Profile*> passedPaths;
38
39 for (TQStringList::const_iterator it = dirs.constBegin(); it != dirs.constEnd(); ++it)
40 processDir(*it, currPath, passedPaths, m_rootProfile);
41}
42
43ProfileEngine::~ProfileEngine()
44{
45 delete m_rootProfile;
46}
47
48void ProfileEngine::processDir(const TQString &dir, const TQString &currPath, TQMap<TQString, Profile*> &passedPaths, Profile *root)
49{
50// kdDebug() << "processDir: " << dir << " " << currPath << endl;
51
52 TQDir qDir(dir);
53 TQStringList entryList = qDir.entryList(TQDir::Dirs);
54 for (TQStringList::const_iterator eit = entryList.constBegin(); eit != entryList.constEnd(); ++eit)
55 {
56 if ((*eit != "..") && (*eit != "."))
57 {
58 TQString dirName = *eit;
59 Profile *profile = 0;
60 if (passedPaths.contains(currPath + dirName))
61 profile = passedPaths[currPath + dirName];
62 else
63 {
64 profile = new Profile(root, dirName);
65 passedPaths[currPath + dirName] = profile;
66 }
67 processDir(dir + *eit + "/", currPath + dirName, passedPaths, profile);
68 }
69 }
70}
71
72TDETrader::OfferList ProfileEngine::offers(const TQString &profileName, OfferType offerType)
73{
74 ProfileListing listing;
75 Profile *profile = 0;
76 getProfileWithListing(listing, &profile, profileName);
77
78 if (!profile)
79 return TDETrader::OfferList();
80
81 TQString constraint = TQString::fromLatin1("[X-TDevelop-Version] == %1").arg(TDEVELOP_PLUGIN_VERSION);
82 switch (offerType) {
83 case Global:
84 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Global'");
85 break;
86 case Project:
87 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Project'");
88 break;
89 case Core:
90 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Core'");
91 break;
92 }
93 TQString constraint_add = "";
94 Profile::EntryList properties = profile->list(Profile::Properties);
95 int i = 0;
96 for (Profile::EntryList::const_iterator it = properties.begin(); it != properties.end(); ++it)
97 constraint_add += TQString::fromLatin1(" %1 '%2' in [X-TDevelop-Properties]").
98 arg((i++)==0?"":"or").arg((*it).name);
99 if (!constraint_add.isEmpty())
100 constraint += " and ( " + constraint_add + " ) ";
101
102//BEGIN debug
103/* kdDebug(9000) << "=============" << endl
104 << " =============" << endl
105 << " ============= Query for Profile:" << endl
106 << " " << constraint << endl << endl << endl;*/
107//END debug
108
109 TDETrader::OfferList list = TDETrader::self()->query(TQString::fromLatin1("TDevelop/Plugin"), constraint);
110 TQStringList names;
111
112/* Wrong, this is not what we want to do.
113 Profile::EntryList disableList = profile->list(Profile::ExplicitDisable);
114 TDETrader::OfferList::iterator it = list.begin();
115 while (it != list.end())
116 {
117 TQString name = (*it)->desktopEntryName();
118 names.append(name);
119 if (profile->hasInEntryList(disableList, name))
120 {
121 it = list.remove(it);
122 continue;
123 }
124 ++it;
125 }
126*/
127 Profile::EntryList enableList = profile->list(Profile::ExplicitEnable);
128 for (Profile::EntryList::const_iterator it = enableList.begin(); it != enableList.end(); ++it)
129 {
130 if (names.contains((*it).name))
131 continue;
132 TQString constraint = TQString::fromLatin1("[X-TDevelop-Version] == %1").arg(TDEVELOP_PLUGIN_VERSION);
133 constraint += TQString::fromLatin1("and [Name] == '%1'").arg((*it).name);
134 TDETrader::OfferList enable = TDETrader::self()->query(TQString::fromLatin1("TDevelop/Plugin"), constraint);
135 list += enable;
136 }
137
138/*//BEGIN debug
139 kdDebug() << "=============" << endl
140 << " =============" << endl
141 << " ============= Plugins for Profile:" << endl;
142 for (TDETrader::OfferList::const_iterator it = list.begin(); it != list.end(); ++it)
143 kdDebug() << " " << (*it)->name() << endl;
144 kdDebug() << endl << endl;
145//END debug*/
146
147 return list;
148}
149
150TDETrader::OfferList ProfileEngine::allOffers(OfferType offerType)
151{
152 TQString constraint = TQString::fromLatin1("[X-TDevelop-Version] == %1").arg(TDEVELOP_PLUGIN_VERSION);
153 switch (offerType) {
154 case Global:
155 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Global'");
156 break;
157 case Project:
158 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Project'");
159 break;
160 case Core:
161 constraint += TQString::fromLatin1(" and [X-TDevelop-Scope] == 'Core'");
162 break;
163 }
164 return TDETrader::self()->query(TQString::fromLatin1("TDevelop/Plugin"), constraint);
165}
166
167void ProfileEngine::getProfileWithListing(ProfileListing &listing, Profile **profile,
168 const TQString &profileName)
169{
170 if (profileName == "KDevelop")
171 *profile = m_rootProfile;
172 else
173 {
174 walkProfiles<ProfileListing>(listing, m_rootProfile);
175 *profile = listing.profiles[profileName];
176 }
177}
178
179KURL::List ProfileEngine::resources(const TQString &profileName, const TQString &nameFilter)
180{
181 ProfileListing listing;
182 Profile *profile = 0;
183 getProfileWithListing(listing, &profile, profileName);
184
185 if (!profile)
186 return KURL::List();
187
188 return resources(profile, nameFilter);
189}
190
191KURL::List ProfileEngine::resources(Profile *profile, const TQString &nameFilter)
192{
193 return profile->resources(nameFilter);
194}
195
196KURL::List ProfileEngine::resourcesRecursive(const TQString &profileName, const TQString &nameFilter)
197{
198 ProfileListing listing;
199 Profile *profile = 0;
200 getProfileWithListing(listing, &profile, profileName);
201 KURL::List resources = profile->resources(nameFilter);
202
203 ProfileListingEx listingEx(nameFilter);
204 walkProfiles<ProfileListingEx>(listingEx, profile);
205
206 resources += listingEx.resourceList;
207 return resources;
208}
209
210void ProfileEngine::diffProfiles(OfferType offerType, const TQString &profile1,
211 const TQString &profile2, TQStringList &unload, TDETrader::OfferList &load)
212{
213 TDETrader::OfferList offers1 = offers(profile1, offerType);
214 TDETrader::OfferList offers2 = offers(profile2, offerType);
215
216 TQStringList offers1List;
217 for (TDETrader::OfferList::const_iterator it = offers1.constBegin();
218 it != offers1.constEnd(); ++it)
219 offers1List.append((*it)->desktopEntryName());
220 TQMap<TQString, KService::Ptr> offers2List;
221 for (TDETrader::OfferList::const_iterator it = offers2.constBegin();
222 it != offers2.constEnd(); ++it)
223 offers2List[(*it)->desktopEntryName()] = *it;
224
225// kdDebug() << "OLD PROFILE: " << offers1List << endl;
226// kdDebug() << "NEW PROFILE: " << offers2List << endl;
227
228 for (TQStringList::const_iterator it = offers1List.constBegin();
229 it != offers1List.constEnd(); ++it)
230 {
231// kdDebug() << "checking: " << *it << endl;
232 if (offers2List.contains(*it))
233 {
234// kdDebug() << " keep" << endl;
235 offers2.remove(offers2List[*it]);
236 }
237 else
238 {
239// kdDebug() << " unload" << endl;
240 unload.append(*it);
241 }
242 }
243 load = offers2;
244}
245
246Profile *ProfileEngine::findProfile(const TQString & profileName)
247{
248 Profile *profile;
249 ProfileListing listing;
250 getProfileWithListing(listing, &profile, profileName);
251 return profile;
252}
253
254void ProfileEngine::addResource(const TQString &profileName, const KURL &url)
255{
256 ProfileListing listing;
257 Profile *profile = 0;
258 getProfileWithListing(listing, &profile, profileName);
259
260 if (!profile)
261 return;
262
263 profile->addResource(url);
264}
ProfileEngine::resources
KURL::List resources(const TQString &profileName, const TQString &nameFilter)
Definition profileengine.cpp:179
ProfileEngine::getProfileWithListing
void getProfileWithListing(ProfileListing &listing, Profile **profile, const TQString &profileName)
Gets a complete listing of available profiles and looks for a profile.
Definition profileengine.cpp:167
ProfileEngine::findProfile
Profile * findProfile(const TQString &profileName)
Finds a profile with given name.
Definition profileengine.cpp:246
ProfileEngine::diffProfiles
void diffProfiles(OfferType offerType, const TQString &profile1, const TQString &profile2, TQStringList &unload, TDETrader::OfferList &load)
Gets the difference between profile1 and profile2.
Definition profileengine.cpp:210
ProfileEngine::OfferType
OfferType
Type of the plugin offer.
Definition profileengine.h:96
ProfileEngine::Core
@ Core
Core plugins.
Definition profileengine.h:99
ProfileEngine::Global
@ Global
Global plugins.
Definition profileengine.h:97
ProfileEngine::Project
@ Project
Project plugins.
Definition profileengine.h:98
ProfileEngine::resourcesRecursive
KURL::List resourcesRecursive(const TQString &profileName, const TQString &nameFilter)
Definition profileengine.cpp:196
ProfileEngine::addResource
void addResource(const TQString &profileName, const KURL &url)
Adds a resource for the profile.
Definition profileengine.cpp:254
ProfileEngine::allOffers
TDETrader::OfferList allOffers(OfferType offerType)
Definition profileengine.cpp:150
ProfileEngine::offers
TDETrader::OfferList offers(const TQString &profileName, OfferType offerType)
Definition profileengine.cpp:72
ProfileEngine::walkProfiles
void walkProfiles(Operation &op, Profile *root)
Walks profiles tree and applies operation op to each profile found in the tree below root (root profi...
Definition profileengine.h:178
ProfileListingEx
Profile resource listing operation.
Definition profileengine.h:49
ProfileListing
Profile listing operation.
Definition profileengine.h:33
Profile
KDevelop profile.
Definition profile.h:30
Profile::ExplicitEnable
@ ExplicitEnable
A list of explicitly enabled plugins (names).
Definition profile.h:44
Profile::Properties
@ Properties
X-TDevelop-Properties defined for this profile.
Definition profile.h:43

KDevelop Shell Profiles Library

Skip menu "KDevelop Shell Profiles Library"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

KDevelop Shell Profiles Library

Skip menu "KDevelop Shell Profiles Library"
  • buildtools
  •   lib
  •     base
  •     parsers
  •       autotools
  •       qmake
  •     widgets
  •   api
  • languages
  •   lib
  •     debugger
  •     designer_integration
  •     interfaces
  • lib
  •   catalog
  •   interfaces
  •     extensions
  •     external
  •     extras
  •   util
  •   widgets
  •     propeditor
  • parts
  •   documentation
  •     interfaces
  • src
  •   profileengine
  •     lib
Generated for KDevelop Shell Profiles Library by doxygen 1.15.0
This website is maintained by Timothy Pearson.