1 /***************************************************************************
2 * Copyright 2004 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
25 #include <kstandarddirs.h>
28 #include <kconfiggroup.h>
29 #include <kio/netaccess.h>
37 QList
<Profile
*> m_children
;
41 QString m_genericName
;
42 QString m_description
;
44 QStringList m_properties
;
45 QStringList m_explicitEnable
;
46 QStringList m_explicitDisable
;
49 Profile::Profile(Profile
*parent
, const QString
&name
)
50 :d(new ProfilePrivate
)
55 d
->m_parent
->addChildProfile(this);
57 QString profileConfig
= KStandardDirs::locate("data", "kdevplatform/profiles" + dirName() + "/profile.config");
58 KConfig
config(profileConfig
);
60 KConfigGroup group
= config
.group("Information");
61 d
->m_genericName
= group
.readEntry("GenericName");
62 d
->m_description
= group
.readEntry("Description");
64 group
= config
.group("Properties");
65 d
->m_properties
= group
.readEntry("List", QStringList());
67 group
= config
.group("Enable");
68 d
->m_explicitEnable
= group
.readEntry("List", QStringList());
70 group
= config
.group("Disable");
71 d
->m_explicitDisable
= group
.readEntry("List", QStringList());
74 Profile::Profile(Profile
*parent
, const QString
&name
, const QString
&genericName
, const QString
&description
)
75 :d(new ProfilePrivate
)
79 d
->m_genericName
= genericName
;
80 d
->m_description
= description
;
82 d
->m_parent
->addChildProfile(this);
88 for (QList
<Profile
*>::iterator it
= d
->m_children
.begin(); it
!= d
->m_children
.end(); ++it
)
93 void Profile::addChildProfile(Profile
*profile
)
95 d
->m_children
.append(profile
);
98 void Profile::removeChildProfile(Profile
*profile
)
100 d
->m_children
.removeAll(profile
);
103 QString
Profile::dirName() const
106 return d
->m_parent
->dirName() + '/' + d
->m_name
;
108 return "/"/* + d->m_name*/;
113 QString profileConfig
= KStandardDirs::locateLocal("data", "kdevplatform/profiles" + dirName() + "/profile.config");
114 KConfig
config(profileConfig
);
116 KConfigGroup group
= config
.group("Information");
117 group
.writeEntry("GenericName", d
->m_genericName
);
118 group
.writeEntry("Description", d
->m_description
);
120 group
= config
.group("Properties");
121 group
.writeEntry("List", d
->m_properties
);
123 group
= config
.group("Enable");
124 group
.writeEntry("List", d
->m_explicitEnable
);
126 group
= config
.group("Disable");
127 group
.writeEntry("List", d
->m_explicitDisable
);
132 Profile::EntryList
Profile::list(List type
)
134 EntryList parentList
;
136 parentList
= d
->m_parent
->list(type
);
137 EntryList list
= parentList
;
138 for (EntryList::iterator it
= list
.begin(); it
!= list
.end(); ++it
)
139 (*it
).derived
= true;
140 QStringList
&personalList
= listByType(type
);
141 for (QStringList::const_iterator it
= personalList
.begin(); it
!= personalList
.end(); ++it
)
142 list
.append(Entry(*it
, false));
146 void Profile::addEntry(List type
, const QString
&value
)
148 QStringList
&list
= listByType(type
);
149 if (!list
.contains(value
))
153 void Profile::removeEntry(List type
, const QString
&value
)
155 QStringList
&list
= listByType(type
);
156 list
.removeAll(value
);
159 QStringList
&Profile::listByType(List type
)
161 static QStringList dummy
;
165 return d
->m_properties
;
167 return d
->m_explicitEnable
;
168 case ExplicitDisable
:
169 return d
->m_explicitDisable
;
174 bool Profile::hasInEntryList(EntryList
&list
, const QString
& value
)
176 for (EntryList::const_iterator it
= list
.constBegin(); it
!= list
.constEnd(); ++it
)
177 if ((*it
).name
== value
)
182 bool Profile::remove()
184 QStringList dirs
= KGlobal::dirs()->findDirs("data", "kdevplatform/profiles" + dirName());
185 if ((dirs
.count() == 1) && dirs
[0].startsWith(QDir::homePath()))
186 return KIO::NetAccess::del(KUrl(dirs
[0]), 0);
190 void Profile::detachFromParent()
193 d
->m_parent
->removeChildProfile(this);
196 KUrl::List
Profile::resources(const QString
&nameFilter
)
198 QStringList resources
;
199 QStringList resourceDirs
= KGlobal::dirs()->resourceDirs("data");
200 for (QStringList::const_iterator it
= resourceDirs
.begin(); it
!= resourceDirs
.end(); ++it
)
203 dir
= dir
+ "kdevplatform/profiles" + dirName();
206 const QFileInfoList infoList
= d
.entryInfoList(QStringList(nameFilter
), QDir::Files
);
207 for (int i
= 0; i
< infoList
.count(); ++i
)
208 resources
.append(infoList
.at(i
).absoluteFilePath());
211 return KUrl::List(resources
);
214 void Profile::addResource(const KUrl
&url
)
216 QString saveLocation
= KGlobal::dirs()->saveLocation("data", "kdevplatform/profiles"+dirName(), true);
217 KIO::FileCopyJob
* job
= KIO::file_copy(url
, KUrl(saveLocation
), -1, KIO::Overwrite
);
221 QList
<Profile
*> Profile::children() const
223 return d
->m_children
;
226 Profile
*Profile::parent() const
231 QString
Profile::name() const
235 QString
Profile::genericName() const
237 return d
->m_genericName
;
239 QString
Profile::description() const
241 return d
->m_description
;