diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch) | |
tree | acaf47eb0fa12142d3896416a69e74cbf5a72242 /src/profileengine | |
download | tdevelop-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')
-rw-r--r-- | src/profileengine/Makefile.am | 3 | ||||
-rw-r--r-- | src/profileengine/editor/Makefile.am | 22 | ||||
-rw-r--r-- | src/profileengine/editor/addprofilewidget.ui | 121 | ||||
-rw-r--r-- | src/profileengine/editor/main.cpp | 45 | ||||
-rw-r--r-- | src/profileengine/editor/profileeditor.cpp | 400 | ||||
-rw-r--r-- | src/profileengine/editor/profileeditor.h | 69 | ||||
-rw-r--r-- | src/profileengine/editor/profileeditorbase.ui | 680 | ||||
-rw-r--r-- | src/profileengine/lib/Mainpage.dox | 10 | ||||
-rw-r--r-- | src/profileengine/lib/Makefile.am | 16 | ||||
-rw-r--r-- | src/profileengine/lib/profile.cpp | 205 | ||||
-rw-r--r-- | src/profileengine/lib/profile.h | 96 | ||||
-rw-r--r-- | src/profileengine/lib/profileengine.cpp | 264 | ||||
-rw-r--r-- | src/profileengine/lib/profileengine.h | 272 |
13 files changed, 2203 insertions, 0 deletions
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 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>AddProfileWidget</class> +<widget class="QWidget"> + <property name="name"> + <cstring>AddProfileWidget</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>312</width> + <height>192</height> + </rect> + </property> + <property name="caption"> + <string>Add Profile</string> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>&Name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>nameEdit</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>nameEdit</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>&Generic name:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>genericNameEdit</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>genericNameEdit</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel3</cstring> + </property> + <property name="text"> + <string>&Description:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>descriptionEdit</cstring> + </property> + </widget> + <widget class="QTextEdit"> + <property name="name"> + <cstring>descriptionEdit</cstring> + </property> + </widget> + </vbox> + </widget> + </vbox> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> 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 <kapplication.h> +#include <kaboutdata.h> +#include <kcmdlineargs.h> + +#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 <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 "profileeditor.h" + +#include <qlayout.h> +#include <klineedit.h> +#include <qtextedit.h> +#include <qpalette.h> + +#include <kdebug.h> +#include <kpushbutton.h> +#include <klistbox.h> +#include <klistview.h> +#include <kcombobox.h> +#include <klocale.h> +#include <kmessagebox.h> +#include <kdialogbase.h> +#include <kglobalsettings.h> +#include <kdeversion.h> + +#include <profile.h> + +#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<ProfileListBuilding, ProfileItem>(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<KListViewItem*>(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<ProfileItem*>(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<EDListItem*>(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<EDListItem*>(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 <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 PROFILEEDITOR_H +#define PROFILEEDITOR_H + +#include <profileengine.h> + +#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 @@ +<!DOCTYPE UI><UI version="3.2" stdsetdef="1"> +<class>ProfileEditorBase</class> +<widget class="QWidget"> + <property name="name"> + <cstring>ProfileEditorBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>637</width> + <height>476</height> + </rect> + </property> + <property name="caption"> + <string>Profile Editor for The KDevelop Platform</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QSplitter" row="0" column="0"> + <property name="name"> + <cstring>splitter2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="QWidgetStack"> + <property name="name"> + <cstring>widgetStack1</cstring> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>WStackPage</cstring> + </property> + <attribute name="id"> + <number>0</number> + </attribute> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLayoutWidget"> + <property name="name"> + <cstring>layout11</cstring> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KPushButton" row="0" column="1"> + <property name="name"> + <cstring>addProfileButton</cstring> + </property> + <property name="text"> + <string>Add Profile</string> + </property> + </widget> + <spacer row="2" column="1"> + <property name="name"> + <cstring>spacer1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>142</height> + </size> + </property> + </spacer> + <widget class="KListView" row="0" column="0" rowspan="3" colspan="1"> + <column> + <property name="text"> + <string>Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Description</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>profilesList</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + <property name="resizeMode"> + <enum>NoColumn</enum> + </property> + </widget> + <widget class="KPushButton" row="1" column="1"> + <property name="name"> + <cstring>removeProfileButton</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove Profile</string> + </property> + </widget> + </grid> + </widget> + </vbox> + </widget> + </widget> + <widget class="QTabWidget"> + <property name="name"> + <cstring>tabWidget2</cstring> + </property> + <widget class="QWidget"> + <property name="name"> + <cstring>tab</cstring> + </property> + <attribute name="title"> + <string>Properties</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KPushButton" row="1" column="2"> + <property name="name"> + <cstring>addPropertyButton</cstring> + </property> + <property name="text"> + <string>Add</string> + </property> + </widget> + <widget class="KComboBox" row="1" column="1"> + <property name="name"> + <cstring>propertyCombo</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="editable"> + <bool>true</bool> + </property> + <property name="autoCompletion"> + <bool>true</bool> + </property> + </widget> + <widget class="KPushButton" row="1" column="3"> + <property name="name"> + <cstring>removePropertyButton</cstring> + </property> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Remove</string> + </property> + </widget> + <widget class="QLayoutWidget" row="0" column="0" rowspan="2" colspan="1"> + <property name="name"> + <cstring>layout7</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>Derived properties:</string> + </property> + </widget> + <widget class="KListBox"> + <property name="name"> + <cstring>derivedPropertiesBox</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget" row="0" column="1" rowspan="1" colspan="3"> + <property name="name"> + <cstring>layout8</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel1_2</cstring> + </property> + <property name="text"> + <string>Own properties:</string> + </property> + </widget> + <widget class="KListBox"> + <property name="name"> + <cstring>ownPropertiesBox</cstring> + </property> + </widget> + </vbox> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>tab</cstring> + </property> + <attribute name="title"> + <string>Lists of Explicitly Enabled && Disabled Plugins</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="QLayoutWidget" row="0" column="2" rowspan="4" colspan="1"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2</cstring> + </property> + <property name="text"> + <string>Enabled:</string> + </property> + </widget> + <widget class="KListView"> + <column> + <property name="text"> + <string>Plugin Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>enabledList</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="QLayoutWidget" row="4" column="2" rowspan="4" colspan="1"> + <property name="name"> + <cstring>layout6</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2_2</cstring> + </property> + <property name="text"> + <string>Disabled:</string> + </property> + </widget> + <widget class="KListView"> + <column> + <property name="text"> + <string>Plugin Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>disabledList</cstring> + </property> + </widget> + </vbox> + </widget> + <widget class="KPushButton" row="2" column="1"> + <property name="name"> + <cstring>delEnabledButton</cstring> + </property> + <property name="text"> + <string><-</string> + </property> + </widget> + <spacer row="3" column="1"> + <property name="name"> + <cstring>spacer2_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + <spacer row="4" column="1"> + <property name="name"> + <cstring>spacer2_3</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="KPushButton" row="6" column="1"> + <property name="name"> + <cstring>delDisabledButton</cstring> + </property> + <property name="text"> + <string><-</string> + </property> + </widget> + <spacer row="7" column="1"> + <property name="name"> + <cstring>spacer2_4</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="QLayoutWidget" row="0" column="0" rowspan="8" colspan="1"> + <property name="name"> + <cstring>layout10</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <property name="margin"> + <number>0</number> + </property> + <property name="spacing"> + <number>0</number> + </property> + <widget class="QLabel"> + <property name="name"> + <cstring>textLabel2_3</cstring> + </property> + <property name="text"> + <string>Available plugins:</string> + </property> + </widget> + <widget class="KListView"> + <column> + <property name="text"> + <string>Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Generic Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>allList</cstring> + </property> + </widget> + <widget class="KLineEdit"> + <property name="name"> + <cstring>allEdit</cstring> + </property> + </widget> + </vbox> + </widget> + <spacer row="0" column="1"> + <property name="name"> + <cstring>spacer2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>20</width> + <height>16</height> + </size> + </property> + </spacer> + <widget class="KPushButton" row="1" column="1"> + <property name="name"> + <cstring>addEnabledButton</cstring> + </property> + <property name="text"> + <string>-></string> + </property> + </widget> + <widget class="KPushButton" row="5" column="1"> + <property name="name"> + <cstring>addDisabledButton</cstring> + </property> + <property name="text"> + <string>-></string> + </property> + </widget> + </grid> + </widget> + <widget class="QWidget"> + <property name="name"> + <cstring>TabPage</cstring> + </property> + <attribute name="title"> + <string>List of Plugins to Be Loaded</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="KListView" row="0" column="0"> + <column> + <property name="text"> + <string>Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Generic Name</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <column> + <property name="text"> + <string>Properties</string> + </property> + <property name="clickable"> + <bool>true</bool> + </property> + <property name="resizable"> + <bool>true</bool> + </property> + </column> + <property name="name"> + <cstring>pluginsView</cstring> + </property> + <property name="allColumnsShowFocus"> + <bool>true</bool> + </property> + </widget> + </grid> + </widget> + </widget> + </widget> + </grid> +</widget> +<connections> + <connection> + <sender>profilesList</sender> + <signal>currentChanged(QListViewItem*)</signal> + <receiver>ProfileEditorBase</receiver> + <slot>profileExecuted(QListViewItem*)</slot> + </connection> + <connection> + <sender>ownPropertiesBox</sender> + <signal>currentChanged(QListBoxItem*)</signal> + <receiver>ProfileEditorBase</receiver> + <slot>propertyExecuted(QListBoxItem*)</slot> + </connection> + <connection> + <sender>addProfileButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>addProfile()</slot> + </connection> + <connection> + <sender>removeProfileButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>removeProfile()</slot> + </connection> + <connection> + <sender>addPropertyButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>addProperty()</slot> + </connection> + <connection> + <sender>removePropertyButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>removeProperty()</slot> + </connection> + <connection> + <sender>profilesList</sender> + <signal>executed(QListViewItem*)</signal> + <receiver>ProfileEditorBase</receiver> + <slot>profileExecuted(QListViewItem*)</slot> + </connection> + <connection> + <sender>profilesList</sender> + <signal>selectionChanged(QListViewItem*)</signal> + <receiver>ProfileEditorBase</receiver> + <slot>profileExecuted(QListViewItem*)</slot> + </connection> + <connection> + <sender>addEnabledButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>addEnabled()</slot> + </connection> + <connection> + <sender>delEnabledButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>delEnabled()</slot> + </connection> + <connection> + <sender>addDisabledButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>addDisabled()</slot> + </connection> + <connection> + <sender>delDisabledButton</sender> + <signal>clicked()</signal> + <receiver>ProfileEditorBase</receiver> + <slot>delDisabled()</slot> + </connection> +</connections> +<tabstops> + <tabstop>profilesList</tabstop> + <tabstop>addProfileButton</tabstop> + <tabstop>removeProfileButton</tabstop> + <tabstop>tabWidget2</tabstop> + <tabstop>derivedPropertiesBox</tabstop> + <tabstop>ownPropertiesBox</tabstop> + <tabstop>propertyCombo</tabstop> + <tabstop>addPropertyButton</tabstop> + <tabstop>removePropertyButton</tabstop> + <tabstop>enabledList</tabstop> + <tabstop>disabledList</tabstop> + <tabstop>pluginsView</tabstop> +</tabstops> +<slots> + <slot>profileExecuted(QListViewItem *item)</slot> + <slot>propertyExecuted(QListBoxItem *item)</slot> + <slot>addProfile()</slot> + <slot>removeProfile()</slot> + <slot>addProperty()</slot> + <slot>removeProperty()</slot> + <slot>addEnabled()</slot> + <slot>delEnabled()</slot> + <slot>addDisabled()</slot> + <slot>delDisabled()</slot> +</slots> +<layoutdefaults spacing="6" margin="11"/> +<includehints> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kcombobox.h</includehint> + <includehint>klineedit.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistbox.h</includehint> + <includehint>klistbox.h</includehint> + <includehint>klistview.h</includehint> + <includehint>klistview.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>kpushbutton.h</includehint> + <includehint>klistview.h</includehint> +</includehints> +</UI> 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 |