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/Makefile.am | 3 + src/profileengine/editor/Makefile.am | 22 + src/profileengine/editor/addprofilewidget.ui | 121 +++++ src/profileengine/editor/main.cpp | 45 ++ src/profileengine/editor/profileeditor.cpp | 400 +++++++++++++++ src/profileengine/editor/profileeditor.h | 69 +++ src/profileengine/editor/profileeditorbase.ui | 680 ++++++++++++++++++++++++++ src/profileengine/lib/Mainpage.dox | 10 + src/profileengine/lib/Makefile.am | 16 + src/profileengine/lib/profile.cpp | 205 ++++++++ src/profileengine/lib/profile.h | 96 ++++ src/profileengine/lib/profileengine.cpp | 264 ++++++++++ src/profileengine/lib/profileengine.h | 272 +++++++++++ 13 files changed, 2203 insertions(+) create mode 100644 src/profileengine/Makefile.am create mode 100644 src/profileengine/editor/Makefile.am create mode 100644 src/profileengine/editor/addprofilewidget.ui create mode 100644 src/profileengine/editor/main.cpp create mode 100644 src/profileengine/editor/profileeditor.cpp create mode 100644 src/profileengine/editor/profileeditor.h create mode 100644 src/profileengine/editor/profileeditorbase.ui create mode 100644 src/profileengine/lib/Mainpage.dox create mode 100644 src/profileengine/lib/Makefile.am create mode 100644 src/profileengine/lib/profile.cpp create mode 100644 src/profileengine/lib/profile.h create mode 100644 src/profileengine/lib/profileengine.cpp create mode 100644 src/profileengine/lib/profileengine.h (limited to 'src/profileengine') diff --git a/src/profileengine/Makefile.am b/src/profileengine/Makefile.am new file mode 100644 index 00000000..3803a6dd --- /dev/null +++ b/src/profileengine/Makefile.am @@ -0,0 +1,3 @@ +SUBDIRS = lib editor +DOXYGEN_EMPTY = YES +include ../../Doxyfile.am diff --git a/src/profileengine/editor/Makefile.am b/src/profileengine/editor/Makefile.am new file mode 100644 index 00000000..c83169cd --- /dev/null +++ b/src/profileengine/editor/Makefile.am @@ -0,0 +1,22 @@ +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)/src/profileengine/lib -I$(top_srcdir)/lib/structure $(all_includes) +METASOURCES = AUTO + +libprofileeditor_la_LDFLAGS = $(all_libraries) +libprofileeditor_la_LIBADD = $(top_builddir)/src/profileengine/lib/libprofileengine.la +noinst_LTLIBRARIES = libprofileeditor.la +libprofileeditor_COMPILE_FIRST = profileeditorbase.h +libprofileeditor_la_SOURCES = profileeditorbase.ui profileeditor.cpp \ + addprofilewidget.ui +noinst_HEADERS = profileeditor.h + + +bin_PROGRAMS = kdevprofileeditor +kdevprofileeditor_LDFLAGS = $(all_libraries) +kdevprofileeditor_LDADD = \ + $(top_builddir)/src/profileengine/lib/libprofileengine.la libprofileeditor.la \ + $(LIB_KDEUI) $(LIB_KIO) +kdevprofileeditor_SOURCES = main.cpp + + diff --git a/src/profileengine/editor/addprofilewidget.ui b/src/profileengine/editor/addprofilewidget.ui new file mode 100644 index 00000000..56a46f1d --- /dev/null +++ b/src/profileengine/editor/addprofilewidget.ui @@ -0,0 +1,121 @@ + +AddProfileWidget + + + AddProfileWidget + + + + 0 + 0 + 312 + 192 + + + + Add Profile + + + + unnamed + + + + layout6 + + + + unnamed + + + 0 + + + 0 + + + + textLabel1 + + + &Name: + + + nameEdit + + + + + nameEdit + + + + + + + layout7 + + + + unnamed + + + 0 + + + 0 + + + + textLabel2 + + + &Generic name: + + + genericNameEdit + + + + + genericNameEdit + + + + + + + layout8 + + + + unnamed + + + 0 + + + 0 + + + + textLabel3 + + + &Description: + + + descriptionEdit + + + + + descriptionEdit + + + + + + + + diff --git a/src/profileengine/editor/main.cpp b/src/profileengine/editor/main.cpp new file mode 100644 index 00000000..52e8d0f1 --- /dev/null +++ b/src/profileengine/editor/main.cpp @@ -0,0 +1,45 @@ +/*************************************************************************** + * 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 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 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 +#include +#include + +#include "profileeditor.h" + +static KCmdLineOptions options[] = +{ + KCmdLineLastOption +}; + +int main(int argc, char **argv) +{ + KAboutData about("kdevprofileeditor", I18N_NOOP("KDevelop Profile Editor"), "1", "", + KAboutData::License_GPL, I18N_NOOP("(c) 2004, The KDevelop Developers"), 0, 0, ""); + about.addAuthor("Alexander Dymo", 0, "adymo@kdevelop.org"); + KCmdLineArgs::init(argc, argv, &about); + KCmdLineArgs::addCmdLineOptions(options); + + KApplication app(argc, argv); + ProfileEditor editor; + editor.show(); + app.setMainWidget(&editor); + + return app.exec(); +} diff --git a/src/profileengine/editor/profileeditor.cpp b/src/profileengine/editor/profileeditor.cpp new file mode 100644 index 00000000..0303793f --- /dev/null +++ b/src/profileengine/editor/profileeditor.cpp @@ -0,0 +1,400 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +#include "profileeditor.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "addprofilewidget.h" + +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; +}; + +class EDListItem: public KListViewItem{ +public: + EDListItem(KListView *parent, const QString &text, bool derived) + : KListViewItem(parent, text), m_derived(derived) + { + } + + bool isDerived() const { return m_derived; } + + virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment) + { + QColorGroup cgNew = cg; + if (m_derived) + cgNew.setColor(QColorGroup::Text, KGlobalSettings::inactiveTextColor()); + KListViewItem::paintCell(p, cgNew, column, width, alignment); + } + +private: + bool m_derived; +}; + + +class ProfileListBuilding { +public: + ProfileItem * operator() (ProfileItem *parent, Profile *profile) + { + parent->setOpen(true); + return new ProfileItem(parent, profile); + } +}; + + +ProfileEditor::ProfileEditor(QWidget *parent, const char *name) + :ProfileEditorBase(parent, name) +{ + refresh(); +} + +void ProfileEditor::refresh() +{ + profilesList->clear(); + + ProfileItem *item = new ProfileItem(profilesList, engine.rootProfile()); + ProfileListBuilding op; + engine.walkProfiles(op, item, engine.rootProfile()); + + profilesList->setSelected(item, true); + profilesList->setCurrentItem(item); + + refreshAvailableList(); + refreshPropertyCombo(); +} + +void ProfileEditor::refreshPropertyCombo() +{ + KTrader::OfferList list = KTrader::self()->query(QString::fromLatin1("KDevelop/Plugin")); + QStringList props; + for (KTrader::OfferList::const_iterator it = list.constBegin(); it != list.constEnd(); ++it) + { + QStringList currProps = (*it)->property("X-KDevelop-Properties").toStringList(); + for (QStringList::const_iterator p = currProps.constBegin(); + p != currProps.constEnd(); ++p) + if (!props.contains(*p)) + props.append(*p); + } + props.sort(); + propertyCombo->insertStringList(props); + propertyCombo->setCurrentText(""); +} + +void ProfileEditor::refreshAvailableList() +{ + //filling a list of available plugins + allList->clear(); + allCore = new KListViewItem(allList, i18n("Core")); + allCore->setOpen(true); + allGlobal = new KListViewItem(allList, i18n("Global")); + allGlobal->setOpen(true); + allProject = new KListViewItem(allList, i18n("Project")); + allProject->setOpen(true); + + KTrader::OfferList olist = engine.allOffers(ProfileEngine::Core); + for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it) + new KListViewItem(allCore, (*it)->desktopEntryName(), (*it)->genericName()); + olist = engine.allOffers(ProfileEngine::Global); + for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it) + new KListViewItem(allGlobal, (*it)->desktopEntryName(), (*it)->genericName()); + olist = engine.allOffers(ProfileEngine::Project); + for (KTrader::OfferList::iterator it = olist.begin(); it != olist.end(); ++it) + new KListViewItem(allProject, (*it)->desktopEntryName(), (*it)->genericName()); +} + +void ProfileEditor::profileExecuted(QListViewItem *item) +{ + if (!item || item->text(0) == "KDevelop") + removeProfileButton->setEnabled(false); + else + removeProfileButton->setEnabled(true); + + fillPropertyList(currentProfile()); + fillEDLists(currentProfile()); + fillPluginsList(currentProfile()); +} + +void ProfileEditor::fillPropertyList(Profile *profile) +{ + derivedPropertiesBox->clear(); + ownPropertiesBox->clear(); + + Profile::EntryList list = profile->list(Profile::Properties); + for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it) + { + if ((*it).derived) + derivedPropertiesBox->insertItem((*it).name); + else + ownPropertiesBox->insertItem((*it).name); + } +} + +void ProfileEditor::fillEDLists(Profile *profile) +{ + //filling a list of enabled plugins + enabledList->clear(); + Profile::EntryList list = profile->list(Profile::ExplicitEnable); + for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it) + new EDListItem(enabledList, (*it).name, (*it).derived); + + //filling a list of disabled plugins + disabledList->clear(); + list = profile->list(Profile::ExplicitDisable); + for (Profile::EntryList::const_iterator it = list.begin(); it != list.end(); ++it) + new EDListItem(disabledList, (*it).name, (*it).derived); +} + +void ProfileEditor::fillPluginsList(Profile *profile) +{ + pluginsView->clear(); + + KListViewItem *core = new KListViewItem(pluginsView, i18n("Core Plugins")); + core->setOpen(true); + KListViewItem *global = new KListViewItem(pluginsView, i18n("Global Plugins")); + global->setOpen(true); + KListViewItem *project = new KListViewItem(pluginsView, i18n("Project Plugins")); + project->setOpen(true); + + KTrader::OfferList coreOffers = engine.offers(profile->name(), ProfileEngine::Core); + for (KTrader::OfferList::const_iterator it = coreOffers.constBegin(); + it != coreOffers.constEnd(); ++it) + new KListViewItem(core, (*it)->desktopEntryName(), (*it)->genericName(), + (*it)->property("X-KDevelop-Properties").toStringList().join(", ")); + + KTrader::OfferList globalOffers = engine.offers(profile->name(), ProfileEngine::Global); + for (KTrader::OfferList::const_iterator it = globalOffers.constBegin(); + it != globalOffers.constEnd(); ++it) + new KListViewItem(global, (*it)->desktopEntryName(), (*it)->genericName(), + (*it)->property("X-KDevelop-Properties").toStringList().join(", ")); + + KTrader::OfferList projectOffers = engine.offers(profile->name(), ProfileEngine::Project); + for (KTrader::OfferList::const_iterator it = projectOffers.constBegin(); + it != projectOffers.constEnd(); ++it) + new KListViewItem(project, (*it)->desktopEntryName(), (*it)->genericName(), + (*it)->property("X-KDevelop-Properties").toStringList().join(", ")); +} + +void ProfileEditor::propertyExecuted(QListBoxItem *item) +{ + removePropertyButton->setEnabled(item != 0); +} + +void ProfileEditor::addProfile() +{ + if (!profilesList->currentItem()) + return; + + KDialogBase dlg(KDialogBase::Plain, i18n("Add Profile"), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok); + dlg.plainPage()->setMargin(0); + (new QVBoxLayout(dlg.plainPage(), 0, 0))->setAutoAdd(true); + AddProfileWidget *prof = new AddProfileWidget(dlg.plainPage()); + prof->nameEdit->setFocus(); + if (dlg.exec() == QDialog::Accepted) + { + Profile *profile = new Profile(currentProfile(), prof->nameEdit->text(), + prof->genericNameEdit->text(), + prof->descriptionEdit->text()); + profilesList->currentItem()->setOpen(true); + new ProfileItem(static_cast(profilesList->currentItem()), profile); + } +} + +void ProfileEditor::removeProfile() +{ + if (KMessageBox::warningContinueCancel(this, i18n("Remove selected profile and all its subprofiles?"), + i18n("Remove Profile"),KStdGuiItem::del()) == KMessageBox::Continue) + { + Profile *profile = currentProfile(); + if (profile->remove()) + { + QListViewItem *item = profilesList->currentItem(); + profilesList->setCurrentItem(item->parent()); + profile->detachFromParent(); + delete profile; + delete item; + } + else + KMessageBox::error(this, i18n("Cannot remove this profile because it is not a local (user-created) profile."), i18n("Remove Profile")); + } +} + +void ProfileEditor::addProperty() +{ + if ( (!propertyCombo->currentText().isEmpty()) && + (ownPropertiesBox->findItem(propertyCombo->currentText()) == 0) && + (derivedPropertiesBox->findItem(propertyCombo->currentText()) == 0) ) + { + ownPropertiesBox->insertItem(propertyCombo->currentText()); + + currentProfile()->addEntry(Profile::Properties, propertyCombo->currentText()); + currentProfile()->save(); + } + + fillPluginsList(currentProfile()); +} + +void ProfileEditor::removeProperty() +{ + currentProfile()->removeEntry(Profile::Properties, ownPropertiesBox->currentText()); + currentProfile()->save(); + + ownPropertiesBox->removeItem(ownPropertiesBox->currentItem()); + + fillPluginsList(currentProfile()); +} + +Profile *ProfileEditor::currentProfile() +{ + ProfileItem *item = dynamic_cast(profilesList->currentItem()); + if (!item) + return 0; + return item->profile(); +} + +void ProfileEditor::accept() +{ +} + +void ProfileEditor::addEnabled() +{ + if (!allList->currentItem() && allEdit->text().isEmpty()) + return; + QString text; + if (!allEdit->text().isEmpty()) + { + text = allEdit->text(); + allEdit->clear(); + } + else + { + if ((allList->currentItem() == allGlobal) || (allList->currentItem() == allProject)) + return; + text = allList->currentItem()->text(0); + } + + if (enabledList->findItem(text, 0) != 0) + return; + if (disabledList->findItem(text, 0) != 0) + { + KMessageBox::error(this, i18n("This plugin is already contained in the list of disabled plugins."), + i18n("Enable Plugin")); + return; + } + currentProfile()->addEntry(Profile::ExplicitEnable, text); + currentProfile()->save(); + fillPluginsList(currentProfile()); + new EDListItem(enabledList, text, false); +} + +void ProfileEditor::delEnabled() +{ + if (!enabledList->currentItem()) + return; + + EDListItem *item = dynamic_cast(enabledList->currentItem()); + if (item && !item->isDerived()) + { + currentProfile()->removeEntry(Profile::ExplicitEnable, enabledList->currentItem()->text(0)); + currentProfile()->save(); + fillPluginsList(currentProfile()); + delete enabledList->currentItem(); + } +} + +void ProfileEditor::addDisabled() +{ + if (!allList->currentItem() && allEdit->text().isEmpty()) + return; + QString text; + if (!allEdit->text().isEmpty()) + { + text = allEdit->text(); + allEdit->clear(); + } + else + { + if ((allList->currentItem() == allGlobal) || (allList->currentItem() == allProject)) + return; + text = allList->currentItem()->text(0); + } + + if (disabledList->findItem(text, 0) != 0) + return; + if (enabledList->findItem(text, 0) != 0) + { + KMessageBox::error(this, i18n("This plugin is already contained in the list of enabled plugins."), + i18n("Disable Plugin")); + return; + } + currentProfile()->addEntry(Profile::ExplicitDisable, text); + currentProfile()->save(); + fillPluginsList(currentProfile()); + new EDListItem(disabledList, text, false); +} + +void ProfileEditor::delDisabled() +{ + if (!disabledList->currentItem()) + return; + + EDListItem *item = dynamic_cast(disabledList->currentItem()); + if (item && !item->isDerived()) + { + currentProfile()->removeEntry(Profile::ExplicitDisable, disabledList->currentItem()->text(0)); + delete disabledList->currentItem(); + currentProfile()->save(); + fillPluginsList(currentProfile()); + } +} + +#include "profileeditor.moc" diff --git a/src/profileengine/editor/profileeditor.h b/src/profileengine/editor/profileeditor.h new file mode 100644 index 00000000..1ec6e91a --- /dev/null +++ b/src/profileengine/editor/profileeditor.h @@ -0,0 +1,69 @@ +/*************************************************************************** + * 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 PROFILEEDITOR_H +#define PROFILEEDITOR_H + +#include + +#include "profileeditorbase.h" + +class QListBoxItem; +class QListViewItem; +class KListViewItem; + +class ProfileEditor : public ProfileEditorBase { + Q_OBJECT +public: + ProfileEditor(QWidget *parent = 0, const char *name = 0); + +public slots: + virtual void removeProperty(); + virtual void addProperty(); + virtual void removeProfile(); + virtual void addProfile(); + virtual void propertyExecuted(QListBoxItem *item); + virtual void profileExecuted(QListViewItem *item); + + virtual void delDisabled(); + virtual void addDisabled(); + virtual void delEnabled(); + virtual void addEnabled(); + + virtual void accept(); + +protected: + void refresh(); + void refreshPropertyCombo(); + void refreshAvailableList(); + + void fillPropertyList(Profile *profile); + void fillEDLists(Profile *profile); + void fillPluginsList(Profile *profile); + + Profile *currentProfile(); + +private: + ProfileEngine engine; + + KListViewItem *allCore; + KListViewItem *allGlobal; + KListViewItem *allProject; +}; + +#endif diff --git a/src/profileengine/editor/profileeditorbase.ui b/src/profileengine/editor/profileeditorbase.ui new file mode 100644 index 00000000..e91fd13d --- /dev/null +++ b/src/profileengine/editor/profileeditorbase.ui @@ -0,0 +1,680 @@ + +ProfileEditorBase + + + ProfileEditorBase + + + + 0 + 0 + 637 + 476 + + + + Profile Editor for The KDevelop Platform + + + + unnamed + + + + splitter2 + + + Vertical + + + + widgetStack1 + + + + WStackPage + + + 0 + + + + unnamed + + + 0 + + + 0 + + + + layout11 + + + + unnamed + + + + addProfileButton + + + Add Profile + + + + + spacer1 + + + Vertical + + + Expanding + + + + 20 + 142 + + + + + + + Name + + + true + + + true + + + + + Description + + + true + + + true + + + + profilesList + + + + 7 + 7 + 0 + 0 + + + + true + + + NoColumn + + + + + removeProfileButton + + + false + + + Remove Profile + + + + + + + + + + tabWidget2 + + + + tab + + + Properties + + + + unnamed + + + + addPropertyButton + + + Add + + + + + propertyCombo + + + + 7 + 0 + 0 + 0 + + + + true + + + true + + + + + removePropertyButton + + + false + + + Remove + + + + + layout7 + + + + unnamed + + + 0 + + + 0 + + + + textLabel1 + + + Derived properties: + + + + + derivedPropertiesBox + + + + + + + layout8 + + + + unnamed + + + 0 + + + 0 + + + + textLabel1_2 + + + Own properties: + + + + + ownPropertiesBox + + + + + + + + + tab + + + Lists of Explicitly Enabled && Disabled Plugins + + + + unnamed + + + + layout5 + + + + unnamed + + + 0 + + + 0 + + + + textLabel2 + + + Enabled: + + + + + + Plugin Name + + + true + + + true + + + + enabledList + + + + + + + layout6 + + + + unnamed + + + 0 + + + 0 + + + + textLabel2_2 + + + Disabled: + + + + + + Plugin Name + + + true + + + true + + + + disabledList + + + + + + + delEnabledButton + + + <- + + + + + spacer2_2 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + spacer2_3 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + delDisabledButton + + + <- + + + + + spacer2_4 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + layout10 + + + + unnamed + + + 0 + + + 0 + + + + textLabel2_3 + + + Available plugins: + + + + + + Name + + + true + + + true + + + + + Generic Name + + + true + + + true + + + + allList + + + + + allEdit + + + + + + + spacer2 + + + Vertical + + + Expanding + + + + 20 + 16 + + + + + + addEnabledButton + + + -> + + + + + addDisabledButton + + + -> + + + + + + + TabPage + + + List of Plugins to Be Loaded + + + + unnamed + + + + + Name + + + true + + + true + + + + + Generic Name + + + true + + + true + + + + + Properties + + + true + + + true + + + + pluginsView + + + true + + + + + + + + + + + profilesList + currentChanged(QListViewItem*) + ProfileEditorBase + profileExecuted(QListViewItem*) + + + ownPropertiesBox + currentChanged(QListBoxItem*) + ProfileEditorBase + propertyExecuted(QListBoxItem*) + + + addProfileButton + clicked() + ProfileEditorBase + addProfile() + + + removeProfileButton + clicked() + ProfileEditorBase + removeProfile() + + + addPropertyButton + clicked() + ProfileEditorBase + addProperty() + + + removePropertyButton + clicked() + ProfileEditorBase + removeProperty() + + + profilesList + executed(QListViewItem*) + ProfileEditorBase + profileExecuted(QListViewItem*) + + + profilesList + selectionChanged(QListViewItem*) + ProfileEditorBase + profileExecuted(QListViewItem*) + + + addEnabledButton + clicked() + ProfileEditorBase + addEnabled() + + + delEnabledButton + clicked() + ProfileEditorBase + delEnabled() + + + addDisabledButton + clicked() + ProfileEditorBase + addDisabled() + + + delDisabledButton + clicked() + ProfileEditorBase + delDisabled() + + + + profilesList + addProfileButton + removeProfileButton + tabWidget2 + derivedPropertiesBox + ownPropertiesBox + propertyCombo + addPropertyButton + removePropertyButton + enabledList + disabledList + pluginsView + + + profileExecuted(QListViewItem *item) + propertyExecuted(QListBoxItem *item) + addProfile() + removeProfile() + addProperty() + removeProperty() + addEnabled() + delEnabled() + addDisabled() + delDisabled() + + + + kpushbutton.h + klistview.h + kpushbutton.h + kpushbutton.h + kcombobox.h + klineedit.h + kpushbutton.h + klistbox.h + klistbox.h + klistview.h + klistview.h + kpushbutton.h + kpushbutton.h + klistview.h + kpushbutton.h + kpushbutton.h + klistview.h + + 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. + +Link with: -lprofileengine + +Include path: -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 * + * * + * 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 +#include + +#include +#include +#include +#include + +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::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 * + * * + * 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 +#include + +/** +@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 EntryList; + + /**Lists which are held by a profile.*/ + enum List { + Properties /** 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 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 * + * * + * 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 + +#include +#include +#include +#include + +#include + +ProfileEngine::ProfileEngine() +{ + QStringList dirs = KGlobal::dirs()->findDirs("data", "kdevelop/profiles"); + + m_rootProfile = new Profile(0, "KDevelop"); + + QString currPath = "/"; + QMap 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 &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(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(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 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 * + * * + * 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.1