1
/***************************************************************************
2
* Copyright (C) 2004 by 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
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#include "profileeditor.h"
22
#include <klineedit.h>
23
#include <qtextedit.h>
27
#include <kpushbutton.h>
29
#include <klistview.h>
30
#include <kcombobox.h>
32
#include <kmessagebox.h>
33
#include <kdialogbase.h>
34
#include <kglobalsettings.h>
35
#include <kdeversion.h>
39
#include "addprofilewidget.h"
41
class ProfileItem: public KListViewItem {
43
ProfileItem(KListView *parent, Profile *profile)
44
:KListViewItem(parent), m_profile(profile)
46
setText(0, profile->genericName());
47
setText(1, profile->description());
50
ProfileItem(KListViewItem *parent, Profile *profile)
51
: KListViewItem(parent), m_profile(profile)
53
setText(0, profile->genericName());
54
setText(1, profile->description());
57
Profile *profile() const { return m_profile; }
63
class EDListItem: public KListViewItem{
65
EDListItem(KListView *parent, const QString &text, bool derived)
66
: KListViewItem(parent, text), m_derived(derived)
70
bool isDerived() const { return m_derived; }
72
virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
74
QColorGroup cgNew = cg;
76
cgNew.setColor(QColorGroup::Text, KGlobalSettings::inactiveTextColor());
77
KListViewItem::paintCell(p, cgNew, column, width, alignment);
85
class ProfileListBuilding {
87
ProfileItem * operator() (ProfileItem *parent, Profile *profile)
89
parent->setOpen(true);
90
return new ProfileItem(parent, profile);
95
ProfileEditor::ProfileEditor(QWidget *parent, const char *name)
96
:ProfileEditorBase(parent, name)
101
void ProfileEditor::refresh()
103
profilesList->clear();
105
ProfileItem *item = new ProfileItem(profilesList, engine.rootProfile());
106
ProfileListBuilding op;
107
engine.walkProfiles<ProfileListBuilding, ProfileItem>(op, item, engine.rootProfile());
109
profilesList->setSelected(item, true);
110
profilesList->setCurrentItem(item);
112
refreshAvailableList();
113
refreshPropertyCombo();
116
void ProfileEditor::refreshPropertyCombo()
118
KTrader::OfferList list = KTrader::self()->query(QString::fromLatin1("KDevelop/Plugin"));
120
for (KTrader::OfferList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it)
122
QStringList currProps = (*it)->property("X-KDevelop-Properties").toStringList();
123
for (QStringList::const_iterator p = currProps.constBegin();
124
p != currProps.constEnd(); ++p)
125
if (!props.contains(*p))
129
propertyCombo->insertStringList(props);
130
propertyCombo->setCurrentText("");
133
void ProfileEditor::refreshAvailableList()
135
//filling a list of available plugins
137
allCore = new KListViewItem(allList, i18n("Core"));
138
allCore->setOpen(true);
139
allGlobal = new KListViewItem(allList, i18n("Global"));
140
allGlobal->setOpen(true);
141
allProject = new KListViewItem(allList, i18n("Project"));
142
allProject->setOpen(true);
144
KTrader::OfferList olist = engine.allOffers(ProfileEngine::Core);
145
for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it)
146
new KListViewItem(allCore, (*it)->desktopEntryName(), (*it)->genericName());
147
olist = engine.allOffers(ProfileEngine::Global);
148
for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it)
149
new KListViewItem(allGlobal, (*it)->desktopEntryName(), (*it)->genericName());
150
olist = engine.allOffers(ProfileEngine::Project);
151
for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it)
152
new KListViewItem(allProject, (*it)->desktopEntryName(), (*it)->genericName());
155
void ProfileEditor::profileExecuted(QListViewItem *item)
157
if (!item || item->text(0) == "KDevelop")
158
removeProfileButton->setEnabled(false);
160
removeProfileButton->setEnabled(true);
162
fillPropertyList(currentProfile());
163
fillEDLists(currentProfile());
164
fillPluginsList(currentProfile());
167
void ProfileEditor::fillPropertyList(Profile *profile)
169
derivedPropertiesBox->clear();
170
ownPropertiesBox->clear();
172
Profile::EntryList list = profile->list(Profile::Properties);
173
for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it)
176
derivedPropertiesBox->insertItem((*it).name);
178
ownPropertiesBox->insertItem((*it).name);
182
void ProfileEditor::fillEDLists(Profile *profile)
184
//filling a list of enabled plugins
185
enabledList->clear();
186
Profile::EntryList list = profile->list(Profile::ExplicitEnable);
187
for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it)
188
new EDListItem(enabledList, (*it).name, (*it).derived);
190
//filling a list of disabled plugins
191
disabledList->clear();
192
list = profile->list(Profile::ExplicitDisable);
193
for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it)
194
new EDListItem(disabledList, (*it).name, (*it).derived);
197
void ProfileEditor::fillPluginsList(Profile *profile)
199
pluginsView->clear();
201
KListViewItem *core = new KListViewItem(pluginsView, i18n("Core Plugins"));
203
KListViewItem *global = new KListViewItem(pluginsView, i18n("Global Plugins"));
204
global->setOpen(true);
205
KListViewItem *project = new KListViewItem(pluginsView, i18n("Project Plugins"));
206
project->setOpen(true);
208
KTrader::OfferList coreOffers = engine.offers(profile->name(), ProfileEngine::Core);
209
for (KTrader::OfferList::const_iterator it = coreOffers.constBegin();
210
it != coreOffers.constEnd(); ++it)
211
new KListViewItem(core, (*it)->desktopEntryName(), (*it)->genericName(),
212
(*it)->property("X-KDevelop-Properties").toStringList().join(", "));
214
KTrader::OfferList globalOffers = engine.offers(profile->name(), ProfileEngine::Global);
215
for (KTrader::OfferList::const_iterator it = globalOffers.constBegin();
216
it != globalOffers.constEnd(); ++it)
217
new KListViewItem(global, (*it)->desktopEntryName(), (*it)->genericName(),
218
(*it)->property("X-KDevelop-Properties").toStringList().join(", "));
220
KTrader::OfferList projectOffers = engine.offers(profile->name(), ProfileEngine::Project);
221
for (KTrader::OfferList::const_iterator it = projectOffers.constBegin();
222
it != projectOffers.constEnd(); ++it)
223
new KListViewItem(project, (*it)->desktopEntryName(), (*it)->genericName(),
224
(*it)->property("X-KDevelop-Properties").toStringList().join(", "));
227
void ProfileEditor::propertyExecuted(QListBoxItem *item)
229
removePropertyButton->setEnabled(item != 0);
232
void ProfileEditor::addProfile()
234
if (!profilesList->currentItem())
237
KDialogBase dlg(KDialogBase::Plain, i18n("Add Profile"), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok);
238
dlg.plainPage()->setMargin(0);
239
(new QVBoxLayout(dlg.plainPage(), 0, 0))->setAutoAdd(true);
240
AddProfileWidget *prof = new AddProfileWidget(dlg.plainPage());
241
prof->nameEdit->setFocus();
242
if (dlg.exec() == QDialog::Accepted)
244
Profile *profile = new Profile(currentProfile(), prof->nameEdit->text(),
245
prof->genericNameEdit->text(),
246
prof->descriptionEdit->text());
247
profilesList->currentItem()->setOpen(true);
248
new ProfileItem(static_cast<KListViewItem*>(profilesList->currentItem()), profile);
252
void ProfileEditor::removeProfile()
254
if (KMessageBox::warningContinueCancel(this, i18n("Remove selected profile and all its subprofiles?"),
255
i18n("Remove Profile"),KStdGuiItem::del()) == KMessageBox::Continue)
257
Profile *profile = currentProfile();
258
if (profile->remove())
260
QListViewItem *item = profilesList->currentItem();
261
profilesList->setCurrentItem(item->parent());
262
profile->detachFromParent();
267
KMessageBox::error(this, i18n("Cannot remove this profile because it is not a local (user-created) profile."), i18n("Remove Profile"));
271
void ProfileEditor::addProperty()
273
if ( (!propertyCombo->currentText().isEmpty()) &&
274
(ownPropertiesBox->findItem(propertyCombo->currentText()) == 0) &&
275
(derivedPropertiesBox->findItem(propertyCombo->currentText()) == 0) )
277
ownPropertiesBox->insertItem(propertyCombo->currentText());
279
currentProfile()->addEntry(Profile::Properties, propertyCombo->currentText());
280
currentProfile()->save();
283
fillPluginsList(currentProfile());
286
void ProfileEditor::removeProperty()
288
currentProfile()->removeEntry(Profile::Properties, ownPropertiesBox->currentText());
289
currentProfile()->save();
291
ownPropertiesBox->removeItem(ownPropertiesBox->currentItem());
293
fillPluginsList(currentProfile());
296
Profile *ProfileEditor::currentProfile()
298
ProfileItem *item = dynamic_cast<ProfileItem*>(profilesList->currentItem());
301
return item->profile();
304
void ProfileEditor::accept()
308
void ProfileEditor::addEnabled()
310
if (!allList->currentItem() && allEdit->text().isEmpty())
313
if (!allEdit->text().isEmpty())
315
text = allEdit->text();
320
if ((allList->currentItem() == allGlobal) || (allList->currentItem() == allProject))
322
text = allList->currentItem()->text(0);
325
if (enabledList->findItem(text, 0) != 0)
327
if (disabledList->findItem(text, 0) != 0)
329
KMessageBox::error(this, i18n("This plugin is already contained in the list of disabled plugins."),
330
i18n("Enable Plugin"));
333
currentProfile()->addEntry(Profile::ExplicitEnable, text);
334
currentProfile()->save();
335
fillPluginsList(currentProfile());
336
new EDListItem(enabledList, text, false);
339
void ProfileEditor::delEnabled()
341
if (!enabledList->currentItem())
344
EDListItem *item = dynamic_cast<EDListItem*>(enabledList->currentItem());
345
if (item && !item->isDerived())
347
currentProfile()->removeEntry(Profile::ExplicitEnable, enabledList->currentItem()->text(0));
348
currentProfile()->save();
349
fillPluginsList(currentProfile());
350
delete enabledList->currentItem();
354
void ProfileEditor::addDisabled()
356
if (!allList->currentItem() && allEdit->text().isEmpty())
359
if (!allEdit->text().isEmpty())
361
text = allEdit->text();
366
if ((allList->currentItem() == allGlobal) || (allList->currentItem() == allProject))
368
text = allList->currentItem()->text(0);
371
if (disabledList->findItem(text, 0) != 0)
373
if (enabledList->findItem(text, 0) != 0)
375
KMessageBox::error(this, i18n("This plugin is already contained in the list of enabled plugins."),
376
i18n("Disable Plugin"));
379
currentProfile()->addEntry(Profile::ExplicitDisable, text);
380
currentProfile()->save();
381
fillPluginsList(currentProfile());
382
new EDListItem(disabledList, text, false);
385
void ProfileEditor::delDisabled()
387
if (!disabledList->currentItem())
390
EDListItem *item = dynamic_cast<EDListItem*>(disabledList->currentItem());
391
if (item && !item->isDerived())
393
currentProfile()->removeEntry(Profile::ExplicitDisable, disabledList->currentItem()->text(0));
394
delete disabledList->currentItem();
395
currentProfile()->save();
396
fillPluginsList(currentProfile());
400
#include "profileeditor.moc"