Commit 2a265cac authored by Andreas Pakulat's avatar Andreas Pakulat

Support loading kconfig data into objects representing the config.

This needed a bit more changes than intended at first. Renamed
the widget-class showing the configuration to make room for a real
CBSConfig class which really only holds the configured information.
parent de9934fb
......@@ -15,8 +15,8 @@ kde4_add_plugin( kdevcustombuildsystem ${custom_SRCS} )
target_link_libraries( kdevcustombuildsystem ${KDEVPLATFORM_PROJECT_LIBRARIES} ${KDEVPLATFORM_INTERFACES_LIBRARIES} ${KDEVPLATFORM_UTIL_LIBRARIES} )
## KCM for the Plugin
set( custom_kcm_SRCS configwidget.cpp custombuildsystemconfig.cpp kcm_custombuildsystem.cpp )
kde4_add_ui_files( custom_kcm_SRCS configwidget.ui custombuildsystemconfig.ui )
set( custom_kcm_SRCS configwidget.cpp custombuildsystemconfigwidget.cpp kcm_custombuildsystem.cpp )
kde4_add_ui_files( custom_kcm_SRCS configwidget.ui custombuildsystemconfigwidget.ui )
kde4_add_kcfg_files( custom_kcm_SRCS kcfg_custombuildsystemconfig.kcfgc )
kde4_add_plugin( kcm_kdevcustombuildsystem ${custom_kcm_SRCS} )
target_link_libraries( kcm_kdevcustombuildsystem ${KDE4_KIO_LIBS} ${KDEVPLATFORM_PROJECT_LIBRARIES} ${KDEVPLATFORM_UTIL_LIBRARIES} )
......
......@@ -27,7 +27,14 @@ namespace ConfigConstants
const QString buildDirKey("BuildDir");
const QString currentConfigKey("CurrentConfiguration");
const QString definesKey("Defines");
const QString includesKey("Includes");
const QString environmentKey("Environment");
const QString toolGroupPrefix("Tool");
const QString toolArguments("Arguments");
const QString toolExecutable("Executable");
const QString toolEnvironment("Environment");
const QString toolType("Type");
const QString customBuildSystemGroup("CustomBuildSystem");
}
#endif
......@@ -27,5 +27,15 @@ ConfigWidget::ConfigWidget( QWidget* parent )
ui->setupUi( this );
}
CustomBuildSystemConfig ConfigWidget::config() const
{
return m_config;
}
void ConfigWidget::loadConfig(CustomBuildSystemConfig cfg)
{
}
#include "configwidget.moc"
......@@ -22,6 +22,8 @@
#include <QWidget>
#include "custombuildsystemconfig.h"
namespace Ui
{
class ConfigWidget;
......@@ -32,8 +34,11 @@ class ConfigWidget : public QWidget
Q_OBJECT
public:
ConfigWidget( QWidget* parent = 0 );
void loadConfig( CustomBuildSystemConfig cfg );
CustomBuildSystemConfig config() const;
private:
Ui::ConfigWidget* ui;
CustomBuildSystemConfig m_config;
};
#endif
......@@ -20,20 +20,29 @@
#ifndef CUSTOMBUILDSYSTEMCONFIG_H
#define CUSTOMBUILDSYSTEMCONFIG_H
#include <QWidget>
#include <QMap>
#include <QList>
#include <QHash>
#include <KUrl>
namespace Ui
struct CustomBuildSystemTool
{
class CustomBuildSystemConfig;
}
enum ActionType { Build = 0, Configure, Install, Clean };
KUrl executable;
QString arguments;
QString envGrp;
ActionType type;
};
class CustomBuildSystemConfig : public QWidget
struct CustomBuildSystemConfig
{
Q_OBJECT
public:
CustomBuildSystemConfig( QWidget* parent = 0 );
private:
Ui::CustomBuildSystemConfig* ui;
QString title;
QString grpName;
KUrl buildDir;
QList<CustomBuildSystemTool> tools;
QMap<QString, QStringList> includes;
QMap<QString, QHash<QString,QString> > defines;
QMap<QString, QString> environments;
};
#endif
#endif
\ No newline at end of file
/************************************************************************
* KDevelop4 Custom Buildsystem Support *
* *
* Copyright 2010 Andreas Pakulat <apaku@gmx.de> *
* *
* 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 3 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, see <http://www.gnu.org/licenses/>. *
************************************************************************/
#include "custombuildsystemconfigwidget.h"
#include <KConfig>
#include "ui_custombuildsystemconfigwidget.h"
#include "configconstants.h"
CustomBuildSystemConfigWidget::CustomBuildSystemConfigWidget( QWidget* parent )
: QWidget( parent ), ui( new Ui::CustomBuildSystemConfigWidget )
{
ui->setupUi( this );
connect( ui->currentConfig, SIGNAL(activated(int)), SLOT(changeCurrentConfig(int)));
connect( ui->configWidget, SIGNAL(changed()), SIGNAL(changed()) );
}
void CustomBuildSystemConfigWidget::loadDefaults()
{
}
void CustomBuildSystemConfigWidget::loadFrom( KConfig* cfg )
{
KConfigGroup grp = cfg->group( ConfigConstants::customBuildSystemGroup );
foreach( const QString& grpName, grp.groupList() ) {
KConfigGroup subgrp = grp.group( grpName );
CustomBuildSystemConfig config;
config.title = subgrp.readEntry( "Title", "" );
config.grpName = grpName;
config.buildDir = subgrp.readEntry( ConfigConstants::buildDirKey, "" );
{
QByteArray tmp = subgrp.readEntry( ConfigConstants::definesKey, QByteArray() );
QDataStream s(tmp);
s.setVersion( QDataStream::Qt_4_5 );
s >> config.defines;
}
{
QByteArray tmp = subgrp.readEntry( ConfigConstants::environmentKey, QByteArray() );
QDataStream s(tmp);
s.setVersion( QDataStream::Qt_4_5 );
s >> config.environments;
}
{
QByteArray tmp = subgrp.readEntry( ConfigConstants::includesKey, QByteArray() );
QDataStream s(tmp);
s.setVersion( QDataStream::Qt_4_5 );
s >> config.includes;
}
foreach( const QString& toolgrpName, subgrp.groupList() ) {
if( toolgrpName.startsWith( ConfigConstants::toolGroupPrefix ) ) {
KConfigGroup toolgrp = subgrp.group( toolgrpName );
CustomBuildSystemTool tool;
tool.arguments = toolgrp.readEntry( ConfigConstants::toolArguments, "" );
tool.executable = toolgrp.readEntry( ConfigConstants::toolExecutable, KUrl() );
tool.envGrp = toolgrp.readEntry( ConfigConstants::toolEnvironment, "default" );
tool.type = CustomBuildSystemTool::ActionType( toolgrp.readEntry( ConfigConstants::toolType, 0 ) );
config.tools << tool;
}
}
configs << config;
ui->currentConfig->addItem( config.title, config.grpName );
}
changeCurrentConfig( ui->currentConfig->findData( grp.readEntry( ConfigConstants::currentConfigKey, "" ) ) );
}
void CustomBuildSystemConfigWidget::saveTo( KConfig* )
{
}
void CustomBuildSystemConfigWidget::changeCurrentConfig( int idx )
{
if( idx == -1 ) {
idx = 0;
}
Q_ASSERT( idx >= 0 && idx < configs.size() );
CustomBuildSystemConfig cfg = configs.at( idx );
ui->configWidget->loadConfig( cfg );
}
#include "custombuildsystemconfigwidget.moc"
......@@ -17,15 +17,34 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
#ifndef CUSTOMBUILDSYSTEMCONFIGWIDGET_H
#define CUSTOMBUILDSYSTEMCONFIGWIDGET_H
#include <QWidget>
#include "custombuildsystemconfig.h"
#include "ui_custombuildsystemconfig.h"
class KConfig;
CustomBuildSystemConfig::CustomBuildSystemConfig( QWidget* parent )
: QWidget( parent ), ui( new Ui::CustomBuildSystemConfig )
namespace Ui
{
ui->setupUi( this );
class CustomBuildSystemConfigWidget;
}
#include "custombuildsystemconfig.moc"
class CustomBuildSystemConfigWidget : public QWidget
{
Q_OBJECT
public:
CustomBuildSystemConfigWidget( QWidget* parent = 0 );
void loadFrom( KConfig* );
void saveTo( KConfig* );
void loadDefaults();
signals:
void changed();
private slots:
void changeCurrentConfig(int);
private:
Ui::CustomBuildSystemConfigWidget* ui;
QList<CustomBuildSystemConfig> configs;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CustomBuildSystemConfig</class>
<widget class="QWidget" name="CustomBuildSystemConfig">
<class>CustomBuildSystemConfigWidget</class>
<widget class="QWidget" name="CustomBuildSystemConfigWidget">
<property name="geometry">
<rect>
<x>0</x>
......
......@@ -127,7 +127,7 @@ QHash< QString, QString > CustomBuildSystem::environment( ProjectBaseItem* item
{
EnvironmentGroupList l( KGlobal::config() );
QHash<QString,QString> envvars;
foreach( QString s, l.createEnvironment( configuration( item->project() ).readEntry(
foreach( QString s, l.createEnvironment( configuration( item->project() ).readEntry(
ConfigConstants::environmentKey, "default" ), QStringList() ) ) {
int idx = s.indexOf( "=" );
envvars.insert( s.left( idx ), s.mid( idx+1 ) );
......@@ -226,7 +226,7 @@ KJob* CustomBuildSystem::createImportJob( ProjectFolderItem* item )
KConfigGroup CustomBuildSystem::configuration( IProject* project ) const
{
KConfigGroup grp = project->projectConfiguration()->group( "CustomBuildSystem" );
KConfigGroup grp = project->projectConfiguration()->group( ConfigConstants::customBuildSystemGroup );
return grp.group( grp.readEntry( ConfigConstants::currentConfigKey ) );
}
......
......@@ -22,7 +22,7 @@
#include <KPluginFactory>
#include <QVBoxLayout>
#include "custombuildsystemconfig.h"
#include "custombuildsystemconfigwidget.h"
#include "kcfg_custombuildsystemconfig.h"
K_PLUGIN_FACTORY(CustomBuildSystemKCModuleFactory, registerPlugin<CustomBuildSystemKCModule>(); )
......@@ -32,10 +32,11 @@ CustomBuildSystemKCModule::CustomBuildSystemKCModule( QWidget* parent, const QVa
: ProjectKCModule<CustomBuildSystemSettings>( CustomBuildSystemKCModuleFactory::componentData(), parent, args )
{
QVBoxLayout* layout = new QVBoxLayout( this );
CustomBuildSystemConfig* w = new CustomBuildSystemConfig;
layout->addWidget( w );
configWidget = new CustomBuildSystemConfigWidget( this );
connect( configWidget, SIGNAL(changed()), SIGNAL(changed()) );
layout->addWidget( configWidget );
addConfig( CustomBuildSystemSettings::self(), w );
addConfig( CustomBuildSystemSettings::self(), configWidget );
load();
}
......@@ -46,16 +47,19 @@ CustomBuildSystemKCModule::~CustomBuildSystemKCModule()
void CustomBuildSystemKCModule::load()
{
KCModule::load();
configWidget->loadFrom( CustomBuildSystemSettings::self()->config() );
}
void CustomBuildSystemKCModule::save()
{
KCModule::save();
configWidget->saveTo( CustomBuildSystemSettings::self()->config() );
}
void CustomBuildSystemKCModule::defaults()
{
KCModule::defaults();
configWidget->loadDefaults();
}
#include "kcm_custombuildsystem.moc"
......
......@@ -40,6 +40,7 @@ public:
virtual void load();
virtual void save();
private:
class CustomBuildSystemConfigWidget* configWidget;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment