summaryrefslogtreecommitdiffstats
path: root/src/tools/gui
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 18:42:24 +0000
commitf508189682b6fba62e08feeb1596f682bad5fff9 (patch)
tree28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/tools/gui
downloadpiklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz
piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/tools/gui')
-rw-r--r--src/tools/gui/Makefile.am7
-rw-r--r--src/tools/gui/tool_config_widget.cpp181
-rw-r--r--src/tools/gui/tool_config_widget.h79
-rw-r--r--src/tools/gui/tool_group_ui.cpp25
-rw-r--r--src/tools/gui/tool_group_ui.h32
-rw-r--r--src/tools/gui/toolchain_config_center.cpp111
-rw-r--r--src/tools/gui/toolchain_config_center.h45
-rw-r--r--src/tools/gui/toolchain_config_widget.cpp301
-rw-r--r--src/tools/gui/toolchain_config_widget.h85
9 files changed, 866 insertions, 0 deletions
diff --git a/src/tools/gui/Makefile.am b/src/tools/gui/Makefile.am
new file mode 100644
index 0000000..0d582eb
--- /dev/null
+++ b/src/tools/gui/Makefile.am
@@ -0,0 +1,7 @@
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
+METASOURCES = AUTO
+
+noinst_LTLIBRARIES = libtoolui.la
+libtoolui_la_LDFLAGS = $(all_libraries)
+libtoolui_la_SOURCES = tool_group_ui.cpp toolchain_config_widget.cpp \
+ tool_config_widget.cpp toolchain_config_center.cpp
diff --git a/src/tools/gui/tool_config_widget.cpp b/src/tools/gui/tool_config_widget.cpp
new file mode 100644
index 0000000..308e61b
--- /dev/null
+++ b/src/tools/gui/tool_config_widget.cpp
@@ -0,0 +1,181 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2004 Alain Gibaud <alain.gibaud@free.fr> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#include "tool_config_widget.h"
+
+#include <qtooltip.h>
+#include <qwidgetstack.h>
+#include <qvgroupbox.h>
+#include <klocale.h>
+
+#include "devices/base/hex_buffer.h"
+#include "tools/list/compile_config.h"
+#include "libgui/project.h"
+#include "common/gui/purl_gui.h"
+#include "tools/list/compile_process.h"
+
+const char * const ToolConfigWidget::ARGUMENTS_TYPE_LABELS[Nb_ArgumentsTypes] = {
+ I18N_NOOP("Automatic"), I18N_NOOP("Custom")
+};
+
+ToolConfigWidget::ToolConfigWidget(Project *project)
+ : ::ConfigWidget(0), _group(0), _project(project),
+ _customOptions(0), _customLibraries(0), _includeDirs(0), _hexFormat(0),
+ _config(0), _tmpConfig(0), _process(0), _tmpProject(0)
+{
+
+ Container *container = new Container(this);
+ container->setColStretch(2, 1);
+ addWidget(container, 0,0, 0,0);
+ QLabel *label = new QLabel(i18n("Configuration:"), container);
+ container->addWidget(label, 0,0, 0,0);
+ _argumentsType = new KComboBox(container);
+ for (uint i=0; i<Nb_ArgumentsTypes; i++)
+ _argumentsType->insertItem(i18n(ARGUMENTS_TYPE_LABELS[i]), i);
+ connect(_argumentsType, SIGNAL(activated(int)), SLOT(updateArguments()));
+ container->addWidget(_argumentsType, 0,0, 1,1);
+ label = new QLabel(i18n("Arguments:"), container);
+ container->addWidget(label, 1,1, 0,0);
+ _arguments = new KLineEdit(container);
+ _arguments->setReadOnly(true);
+ container->addWidget(_arguments, 1,1, 1,2);
+ KPushButton *button = new KPushButton(KGuiItem(QString::null, "help"), container);
+ connect(button, SIGNAL(clicked()), SIGNAL(displayHelp()));
+ container->addWidget(button, 1,1, 3,3);
+ _argumentsEditor = new EditListBox(1, container, "arguments_editor", EditListBox::DuplicatesAllowed,
+ EditListBox::Add | EditListBox::Remove | EditListBox::UpDown | EditListBox::RemoveAll | EditListBox::Reset);
+ connect(_argumentsEditor, SIGNAL(changed()), SLOT(updateArguments()));
+ connect(_argumentsEditor, SIGNAL(reset()), SLOT(resetCustomArguments()));
+ container->addWidget(_argumentsEditor, 2,2, 0,3);
+
+ _container = new Container(container);
+ _container->setColStretch(2, 1);
+ container->addWidget(_container, 3,3, 0,3);
+
+ connect(this, SIGNAL(changed()), SLOT(updateArguments()));
+}
+
+void ToolConfigWidget::init(Tool::Category category, const Tool::Group &group)
+{
+ _category = category;
+ _group = &group;
+ _config = _group->createConfig(_project);
+ _tmpProject = new Project(PURL::Url());
+ _tmpConfig = _group->createConfig(_tmpProject);
+ Compile::Data data(_category, QValueList<Compile::TodoItem>(), QString::null, _project, Compile::NormalLinking);
+ _process = _group->createCompileProcess(data, 0);
+
+ initEntries();
+ createCustomOptionsEntry();
+}
+
+ToolConfigWidget::~ToolConfigWidget()
+{
+ delete _process;
+ delete _tmpConfig;
+ delete _tmpProject;
+ delete _config;
+}
+
+PURL::DirectoriesWidget *ToolConfigWidget::createDirectoriesEntry(const QString &text)
+{
+ uint row = container()->numRows();
+ PURL::DirectoriesWidget *sdw = new PURL::DirectoriesWidget(text, _project ? _project->directory().path() : QString::null, container());
+ connect(sdw, SIGNAL(changed()), SIGNAL(changed()));
+ container()->addWidget(sdw, row,row, 0,2);
+ return sdw;
+}
+
+void ToolConfigWidget::createCustomOptionsEntry()
+{
+ uint row = container()->numRows();
+ QLabel *label = new QLabel(i18n("Custom options:"), container());
+ container()->addWidget(label, row,row, 0,0);
+ _customOptions = new QLineEdit(container());
+ connect(_customOptions, SIGNAL(textChanged(const QString &)), SIGNAL(changed()));
+ container()->addWidget(_customOptions, row,row, 1,2);
+}
+
+void ToolConfigWidget::createCustomLibrariesEntry()
+{
+ uint row = container()->numRows();
+ QLabel *label = new QLabel(i18n("Custom libraries:"), container());
+ container()->addWidget(label, row,row, 0,0);
+ _customLibraries = new QLineEdit(container());
+ connect(_customLibraries, SIGNAL(textChanged(const QString &)), SIGNAL(changed()));
+ QToolTip::add(_customLibraries, i18n("<qt>This values will be placed after the linked objects.</qt>")) ;
+ container()->addWidget(_customLibraries, row,row, 1,2);
+}
+
+void ToolConfigWidget::createHexFormatEntry()
+{
+ uint row = container()->numRows();
+ QLabel *label = new QLabel(i18n("Hex file format:"), container());
+ container()->addWidget(label, row,row, 0,0);
+ _hexFormat = new QComboBox(container());
+ connect(_hexFormat, SIGNAL(activated(int)), SIGNAL(changed()));
+ for (uint i=0; i<HexBuffer::Nb_Formats; i++)
+ _hexFormat->insertItem(HexBuffer::FORMATS[i]);
+ _hexFormat->insertItem(i18n("as in LIST directive"));
+ container()->addWidget(_hexFormat, row,row, 1,1);
+}
+
+void ToolConfigWidget::loadConfig()
+{
+ loadConfig(*_config);
+ if ( _config->customArguments(_category).isEmpty() ) resetCustomArguments();
+ else updateArguments();
+}
+
+void ToolConfigWidget::resetCustomArguments()
+{
+ _argumentsEditor->setTexts(arguments(AutomaticArguments));
+ updateArguments();
+}
+
+void ToolConfigWidget::loadConfig(const Compile::Config &config)
+{
+ _argumentsType->setCurrentItem(config.hasCustomArguments(_category) ? CustomArguments : AutomaticArguments);
+ _argumentsEditor->setTexts(config.customArguments(_category));
+ if (_includeDirs) _includeDirs->setDirectories(config.rawIncludeDirs(_category)) ;
+ if (_customOptions) _customOptions->setText(config.rawCustomOptions(_category));
+ if (_customLibraries) _customLibraries->setText(config.rawCustomLibraries(_category));
+ if (_hexFormat) _hexFormat->setCurrentItem(config.hexFormat());
+}
+
+void ToolConfigWidget::saveConfig(Compile::Config &config) const
+{
+ config.setHasCustomArguments(_category, _argumentsType->currentItem()==CustomArguments);
+ config.setCustomArguments(_category, _argumentsEditor->texts());
+ if (_includeDirs) config.setRawIncludeDirs(_category, _includeDirs->directories());
+ if (_customOptions) config.setRawCustomOptions(_category, _customOptions->text());
+ if (_customLibraries) config.setRawCustomLibraries(_category, _customLibraries->text());
+ if (_hexFormat) config.setHexFormat(HexBuffer::Format(_hexFormat->currentItem()));
+}
+
+QStringList ToolConfigWidget::arguments(ArgumentsType type) const
+{
+ if ( _tmpConfig==0 ) return QStringList();
+ saveConfig(*_tmpConfig);
+ if ( type==AutomaticArguments ) return _process->genericArguments(*_tmpConfig);
+ return _argumentsEditor->texts();
+}
+
+void ToolConfigWidget::updateArguments()
+{
+ ArgumentsType type = ArgumentsType(_argumentsType->currentItem());
+ if ( type==AutomaticArguments ) {
+ _argumentsEditor->hide();
+ _container->show();
+ } else {
+ _argumentsEditor->show();
+ _container->hide();
+ }
+ _arguments->setText(arguments(type).join(" "));
+}
diff --git a/src/tools/gui/tool_config_widget.h b/src/tools/gui/tool_config_widget.h
new file mode 100644
index 0000000..5b38753
--- /dev/null
+++ b/src/tools/gui/tool_config_widget.h
@@ -0,0 +1,79 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2004 Alain Gibaud <alain.gibaud@free.fr> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef TOOL_CONFIG_WIDGET_H
+#define TOOL_CONFIG_WIDGET_H
+
+#include <qcombobox.h>
+#include <qlayout.h>
+#include <qtabwidget.h>
+#include <qvaluevector.h>
+#include <kcombobox.h>
+#include <klineedit.h>
+
+#include "common/gui/container.h"
+#include "tools/base/generic_tool.h"
+#include "tools/base/tool_group.h"
+#include "common/gui/config_widget.h"
+#include "common/gui/editlistbox.h"
+namespace PURL { class DirectoriesWidget; }
+
+class ToolConfigWidget : public ::ConfigWidget
+{
+Q_OBJECT
+public:
+ ToolConfigWidget(Project *project);
+ void init(Tool::Category category, const Tool::Group &group);
+ virtual ~ToolConfigWidget();
+
+signals:
+ void changed();
+ void displayHelp();
+
+public slots:
+ virtual void loadConfig();
+ virtual void saveConfig() { saveConfig(*_config); }
+
+private slots:
+ void updateArguments();
+ void resetCustomArguments();
+
+protected:
+ const Tool::Group *_group;
+ Tool::Category _category;
+ Project *_project;
+ QLineEdit *_customOptions, *_customLibraries;
+ PURL::DirectoriesWidget *_includeDirs;
+ QComboBox *_hexFormat;
+
+ Container *container() { return _container; }
+ PURL::DirectoriesWidget * createDirectoriesEntry(const QString &label);
+ void createIncludeDirectoriesEntry() { _includeDirs = createDirectoriesEntry(i18n("Include directories:")); }
+ void createCustomOptionsEntry();
+ void createCustomLibrariesEntry();
+ void createHexFormatEntry();
+ virtual void initEntries() = 0;
+ virtual void loadConfig(const Compile::Config &config);
+ virtual void saveConfig(Compile::Config &config) const;
+
+private:
+ enum ArgumentsType { AutomaticArguments = 0, CustomArguments, Nb_ArgumentsTypes };
+ static const char * const ARGUMENTS_TYPE_LABELS[Nb_ArgumentsTypes];
+ Compile::Config *_config, *_tmpConfig;
+ Compile::Process *_process;
+ Project *_tmpProject;
+ KComboBox *_argumentsType;
+ KLineEdit *_arguments;
+ EditListBox *_argumentsEditor;
+ Container *_container;
+
+ QStringList arguments(ArgumentsType type) const;
+};
+
+#endif
diff --git a/src/tools/gui/tool_group_ui.cpp b/src/tools/gui/tool_group_ui.cpp
new file mode 100644
index 0000000..9bb02dd
--- /dev/null
+++ b/src/tools/gui/tool_group_ui.cpp
@@ -0,0 +1,25 @@
+/***************************************************************************
+ * Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.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. *
+ ***************************************************************************/
+#include "tool_group_ui.h"
+
+#include "tool_config_widget.h"
+#include "toolchain_config_widget.h"
+
+ToolchainConfigWidget *Tool::GroupUI::toolchainConfigWidgetFactory(QWidget *parent) const
+{
+ return new ToolchainConfigWidget(static_cast<const Group &>(group()), parent);
+}
+
+ToolConfigWidget *Tool::GroupUI::createConfigWidget(Category category, ::Project *project) const
+{
+ ToolConfigWidget *cw = configWidgetFactory(category, project);
+ Q_ASSERT(cw);
+ cw->init(category, static_cast<const Group &>(group()));
+ return cw;
+}
diff --git a/src/tools/gui/tool_group_ui.h b/src/tools/gui/tool_group_ui.h
new file mode 100644
index 0000000..4d1f42c
--- /dev/null
+++ b/src/tools/gui/tool_group_ui.h
@@ -0,0 +1,32 @@
+/***************************************************************************
+ * Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.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. *
+ ***************************************************************************/
+#ifndef TOOL_GROUP_UI_H
+#define TOOL_GROUP_UI_H
+
+#include "tools/base/tool_group.h"
+#include "tools/base/generic_tool.h"
+class ToolConfigWidget;
+class ToolchainConfigWidget;
+
+namespace Tool
+{
+
+class GroupUI : public ::Group::BaseGui
+{
+public:
+ ToolConfigWidget *createConfigWidget(Category category, ::Project *project) const;
+ virtual ToolConfigWidget *configWidgetFactory(Category category, ::Project *project) const = 0;
+ virtual ToolchainConfigWidget *toolchainConfigWidgetFactory(QWidget *parent) const;
+};
+
+inline const GroupUI &groupui(const Base &base) { return static_cast<const GroupUI &>(*base.group().gui()); }
+
+} // namespace
+
+#endif
diff --git a/src/tools/gui/toolchain_config_center.cpp b/src/tools/gui/toolchain_config_center.cpp
new file mode 100644
index 0000000..c8b889d
--- /dev/null
+++ b/src/tools/gui/toolchain_config_center.cpp
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * Copyright (C) 2005-2007 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2004 Alain Gibaud <alain.gibaud@free.fr> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#include "toolchain_config_center.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <kiconloader.h>
+
+#include "tools/list/tools_config_widget.h"
+#include "tools/list/compile_config.h"
+#include "tools/list/tool_list.h"
+#include "toolchain_config_widget.h"
+#include "tool_group_ui.h"
+
+ToolchainsConfigCenter::ToolchainsConfigCenter(const Tool::Group &sgroup, QWidget *parent)
+ : TreeListDialog(parent, "configure_toolchains_dialog", true,
+ i18n("Configure Toolchains"), Ok|User1|User2|Cancel, Cancel, false)
+{
+ setButtonGuiItem(User1, KStdGuiItem::reset());
+ setButtonGuiItem(User2, KGuiItem(i18n("Update"), "reload"));
+
+ _titleBox->addStretch(1);
+ _infoButton = new KPushButton(KGuiItem(QString::null, "viewmag"), _frame);
+ connect(_infoButton, SIGNAL(clicked()), SLOT(showInformationDialog()));
+ _titleBox->addWidget(_infoButton);
+
+ QWidget *current = 0;
+ FOR_EACH(PURL::SourceFamily, family) {
+ Tool::Lister::ConstIterator it;
+ for (it=Tool::lister().begin(); it!=Tool::lister().end(); ++it) {
+ PURL::FileType type = it.data()->implementationType(family.data().toolType);
+ if ( type==PURL::Nb_FileTypes || type.data().sourceFamily!=family ) continue;
+ if ( family==PURL::SourceFamily::Asm && it.data()->implementationType(PURL::ToolType::Compiler)!=PURL::Nb_FileTypes ) continue;
+ QStringList names = family.label();
+ names += it.data()->label();
+ QWidget *page = addPage(names);
+ QVBoxLayout *vbox = new QVBoxLayout(page);
+ ToolchainConfigWidget *tcw = static_cast<const ::Tool::GroupUI *>(it.data()->gui())->toolchainConfigWidgetFactory(page);
+ tcw->init();
+ tcw->loadConfig();
+ vbox->addWidget(tcw);
+ _pages[page] = tcw;
+ if ( it.key()==sgroup.name() ) current = page;
+ }
+ }
+ showPage(current);
+ aboutToShowPageSlot(current);
+ connect(this, SIGNAL(aboutToShowPage(QWidget *)), SLOT(aboutToShowPageSlot(QWidget *)));
+}
+
+void ToolchainsConfigCenter::aboutToShowPageSlot(QWidget *page)
+{
+ if ( !_pages.contains(page) ) _infoButton->hide();
+ else {
+ _infoButton->show();
+ QTimer::singleShot(0, _pages[page], SLOT(detect()));
+ }
+}
+
+void ToolchainsConfigCenter::slotApply()
+{
+ QMap<QWidget *, ToolchainConfigWidget *>::iterator it;
+ for (it=_pages.begin(); it!=_pages.end(); ++it) it.data()->saveConfig();
+}
+
+void ToolchainsConfigCenter::slotOk()
+{
+ slotApply();
+ accept();
+}
+
+ToolchainConfigWidget *ToolchainsConfigCenter::current() const
+{
+ int i = activePageIndex();
+ if ( i==-1 ) return 0;
+ QMap<QWidget *, ToolchainConfigWidget *>::const_iterator it;
+ for (it=_pages.begin(); it!=_pages.end(); ++it)
+ if ( pageIndex(it.key())==i ) return it.data();
+ Q_ASSERT(false);
+ return 0;
+}
+
+void ToolchainsConfigCenter::slotUser1()
+{
+ ToolchainConfigWidget *tcw = current();
+ if (tcw) {
+ tcw->loadConfig();
+ tcw->forceDetect();
+ }
+}
+
+void ToolchainsConfigCenter::slotUser2()
+{
+ ToolchainConfigWidget *tcw = current();
+ if (tcw) tcw->forceDetect();
+}
+
+void ToolchainsConfigCenter::showInformationDialog()
+{
+ ToolchainConfigWidget *tcw = current();
+ Q_ASSERT(tcw);
+ TextEditorDialog dialog(tcw->group().informationText(), tcw->group().label(), true, this);
+ dialog.exec();
+}
diff --git a/src/tools/gui/toolchain_config_center.h b/src/tools/gui/toolchain_config_center.h
new file mode 100644
index 0000000..4b2110b
--- /dev/null
+++ b/src/tools/gui/toolchain_config_center.h
@@ -0,0 +1,45 @@
+/***************************************************************************
+ * Copyright (C) 2005 Nicolas Hadacek <hadacek@kde.org> *
+ * Copyright (C) 2004 Alain Gibaud <alain.gibaud@free.fr> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef TOOLCHAIN_CONFIG_CENTER_H
+#define TOOLCHAIN_CONFIG_CENTER_H
+
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qlineedit.h>
+#include <qwidgetstack.h>
+
+#include "tools/gui/tool_config_widget.h"
+#include "common/gui/dialog.h"
+class ToolchainConfigWidget;
+
+class ToolchainsConfigCenter : public TreeListDialog
+{
+Q_OBJECT
+public:
+ ToolchainsConfigCenter(const Tool::Group &group, QWidget *parent);
+
+public slots:
+ virtual void slotOk();
+ virtual void slotApply();
+ virtual void slotUser1();
+ virtual void slotUser2();
+
+private slots:
+ void aboutToShowPageSlot(QWidget *page);
+ void showInformationDialog();
+
+private:
+ KPushButton *_infoButton;
+ QMap<QWidget *, ToolchainConfigWidget *> _pages;
+
+ ToolchainConfigWidget *current() const;
+};
+
+#endif
diff --git a/src/tools/gui/toolchain_config_widget.cpp b/src/tools/gui/toolchain_config_widget.cpp
new file mode 100644
index 0000000..aede699
--- /dev/null
+++ b/src/tools/gui/toolchain_config_widget.cpp
@@ -0,0 +1,301 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.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. *
+ ***************************************************************************/
+#include "toolchain_config_widget.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qgroupbox.h>
+#include <qtabwidget.h>
+#include <kiconloader.h>
+#include <ktextedit.h>
+
+#include "tools/list/compile_config.h"
+#include "common/gui/purl_gui.h"
+#include "common/global/process.h"
+#include "common/gui/container.h"
+
+//----------------------------------------------------------------------------
+ToolchainConfigWidget::ToolchainConfigWidget(const Tool::Group &group, QWidget *parent)
+ : ::ConfigWidget(parent),
+ _group(group), _dirty(false), _outputType(0), _devicesData(group.nbCheckDevices())
+{
+ _config = group.createConfig(0);
+}
+
+ToolchainConfigWidget::~ToolchainConfigWidget()
+{
+ delete _config;
+}
+
+void ToolchainConfigWidget::init()
+{
+ Container *container = new Container(this, Container::Sunken);
+ addWidget(container, 0,0, 0,3);
+ container->setColStretch(3, 1);
+
+ uint row = 0;
+ QLabel *label = new QLabel(Compile::DirectoryType(Compile::DirectoryType::Executable).label() + ":", container);
+ container->addWidget(label, row,row, 0,0);
+ _dirs[Compile::DirectoryType::Executable] = new PURL::DirectoryWidget(container);
+ connect(_dirs[Compile::DirectoryType::Executable], SIGNAL(changed()), SLOT(forceDetect()));
+ container->addWidget(_dirs[Compile::DirectoryType::Executable], row,row, 1,3);
+ row++;
+
+ label = new QLabel(i18n("Executable Type:"), container);
+ container->addWidget(label, row,row, 0,0);
+ _execType = new QComboBox(container);
+ FOR_EACH(Tool::ExecutableType, type) _execType->insertItem(type.label());
+ connect(_execType, SIGNAL(activated(int)), SLOT(forceDetect()));
+ container->addWidget(_execType, row,row, 1,2);
+ row++;
+
+ uint nbOutputTypes = 0;
+ FOR_EACH(Tool::OutputExecutableType, type)
+ if ( _group.hasOutputExecutableType(type) ) nbOutputTypes++;
+ if ( nbOutputTypes>1 ) {
+ label = new QLabel(i18n("Output Executable Type:"), container);
+ container->addWidget(label, row,row, 0,0);
+ _outputType = new KeyComboBox<Tool::OutputExecutableType>(container);
+ FOR_EACH(Tool::OutputExecutableType, type)
+ if ( _group.hasOutputExecutableType(type) ) _outputType->appendItem(type, type.label());
+ connect(_outputType->widget(), SIGNAL(activated(int)), SLOT(forceDetect()));
+ container->addWidget(_outputType->widget(), row,row, 1,1);
+ row++;
+ }
+
+ addCustomExecutableOptions(container);
+
+ FOR_EACH(Tool::Category, k) {
+ const Tool::Base *base = _group.base(k);
+ if ( base==0 ) continue;
+ label = new QLabel(k.label(), container);
+ container->addWidget(label, row,row, 0,0);
+ _data[k].label = new QLabel(container);
+ container->addWidget(_data[k].label, row,row, 1,1);
+ _data[k].button = new KPushButton(KGuiItem(QString::null, "viewmag"), container);
+ connect(_data[k].button, SIGNAL(clicked()), SLOT(showDetails()));
+ container->addWidget(_data[k].button, row,row, 2,2);
+ row++;
+ }
+
+ label = new QLabel(i18n("Device detection:"), container);
+ container->addWidget(label, row,row, 0,0);
+ _devicesLabel = new QLabel(container);
+ container->addWidget(_devicesLabel, row,row, 1,1);
+ KPushButton *button = new KPushButton(KGuiItem(QString::null, "viewmag"), container);
+ connect(button, SIGNAL(clicked()), SLOT(showDeviceDetails()));
+ container->addWidget(button, row,row, 2,2);
+ row++;
+
+ row = numRows();
+ FOR_EACH(Compile::DirectoryType, type) {
+ if ( type==Compile::DirectoryType::Executable ) continue;
+ if ( !_group.hasDirectory(type) ) _dirs[type] = 0;
+ else {
+ label = new QLabel(type.label() + ":", this);
+ addWidget(label, row,row, 0,0);
+ _dirs[type] = new PURL::DirectoryWidget(this);
+ addWidget(_dirs[type], row,row, 1,3);
+ row++;
+ }
+ }
+
+ if ( !_group.comment().isEmpty() ) {
+ KTextEdit *w = new KTextEdit(_group.comment(), QString::null, this);
+ w->setReadOnly(true);
+ w->setWordWrap(QTextEdit::WidgetWidth);
+ addWidget(w, row,row, 0,3);
+ row++;
+ }
+
+ setColStretch(3, 1);
+}
+
+void ToolchainConfigWidget::loadConfig()
+{
+ _execType->blockSignals(true);
+ _execType->setCurrentItem(Compile::Config::withWine(_group) ? Tool::ExecutableType::Windows : Tool::ExecutableType::Unix);
+ _execType->blockSignals(false);
+ if (_outputType) {
+ _outputType->widget()->blockSignals(true);
+ _outputType->setCurrentItem(Compile::Config::outputExecutableType(_group));
+ _outputType->widget()->blockSignals(false);
+ }
+ FOR_EACH(Compile::DirectoryType, type) {
+ if ( _dirs[type]==0 ) continue;
+ _dirs[type]->blockSignals(true);
+ _dirs[type]->setDirectory(Compile::Config::directory(_group, type));
+ _dirs[type]->blockSignals(false);
+ }
+ _dirty = true;
+}
+
+void ToolchainConfigWidget::saveConfig()
+{
+ Compile::Config::setWithWine(_group, withWine());
+ if (_outputType) Compile::Config::setOutputExecutableType(_group, outputType());
+ FOR_EACH(Compile::DirectoryType, type)
+ if ( _dirs[type] ) Compile::Config::setDirectory(_group, type, _dirs[type]->directory());
+}
+
+void ToolchainConfigWidget::forceDetect()
+{
+ _dirty = true;
+ detect();
+}
+
+void ToolchainConfigWidget::checkExecutableDone()
+{
+ FOR_EACH(Tool::Category, i) {
+ if ( _data[i].process!=sender() ) continue;
+ if ( _data[i].process->state()==::Process::Timedout ) {
+ _data[i].label->setText(i18n("Timeout"));
+ return;
+ }
+ _data[i].checkLines = _data[i].process->sout() + _data[i].process->serr();
+ const Tool::Base *base = _group.base(i);
+ QString exec = base->baseExecutable(withWine(), outputType());
+ if ( base->checkExecutableResult(withWine(), _data[i].checkLines) ) _data[i].label->setText(i18n("\"%1\" found").arg(exec));
+ else _data[i].label->setText(i18n("\"%1\" not recognized").arg(exec));
+ break;
+ }
+}
+
+void ToolchainConfigWidget::checkDevicesDone()
+{
+ for(uint i=0; i<_devicesData.count(); i++) {
+ if ( _devicesData[i].process!=sender() ) continue;
+ if ( _devicesData[i].process->state()==::Process::Timedout ) {
+ _devicesLabel->setText(i18n("Timeout"));
+ return;
+ }
+ _devicesData[i].checkLines = _devicesData[i].process->sout() + _devicesData[i].process->serr();
+ _devicesData[i].done = true;
+ break;
+ }
+ QValueList<const Device::Data *> list;
+ for(uint i=0; i<_devicesData.count(); i++) {
+ if ( !_devicesData[i].done ) return;
+ list += _group.getSupportedDevices(_devicesData[i].checkLines.join("\n"));
+ }
+ _devicesLabel->setText(i18n("Detected (%1)").arg(list.count()));
+}
+
+bool ToolchainConfigWidget::withWine() const
+{
+ return ( _execType->currentItem()==Tool::ExecutableType::Windows );
+}
+
+Tool::OutputExecutableType ToolchainConfigWidget::outputType() const
+{
+ return (_outputType==0 ? Compile::Config::outputExecutableType(_group) : _outputType->currentItem());
+}
+
+QString ToolchainConfigWidget::baseExecutable(Tool::Category category) const
+{
+ return _group.base(category)->baseExecutable(withWine(), outputType());
+}
+
+::Process::LineOutput *ToolchainConfigWidget::checkExecutableProcess(Tool::Category category) const
+{
+ PURL::Directory execDir = _dirs[Compile::DirectoryType::Executable]->directory();
+ return _group.base(category)->checkExecutableProcess(execDir, withWine(), outputType());
+}
+
+::Process::LineOutput *ToolchainConfigWidget::checkDevicesProcess(uint i) const
+{
+ PURL::Directory execDir = _dirs[Compile::DirectoryType::Executable]->directory();
+ return _group.checkDevicesProcess(i, execDir, withWine());
+}
+
+void ToolchainConfigWidget::detect()
+{
+ if ( !_dirty ) return;
+ FOR_EACH(Tool::Category, k) {
+ if ( _data[k].label==0 ) continue;
+ if ( !_group.base(k)->checkExecutable() ) _data[k].label->setText(i18n("Unknown"));
+ else {
+ delete _data[k].process;
+ _data[k].checkLines.clear();
+ _data[k].process = checkExecutableProcess(k);
+ _data[k].command = _data[k].process->prettyCommand();
+ connect(_data[k].process, SIGNAL(done(int)), SLOT(checkExecutableDone()));
+ connect(_data[k].process, SIGNAL(timeout()), SLOT(checkExecutableDone()));
+ QString exec = baseExecutable(k);
+ if ( !_data[k].process->start(10000) ) _data[k].label->setText(i18n("\"%1\" not found").arg(exec));
+ else _data[k].label->setText(i18n("Detecting \"%1\"...").arg(exec));
+ }
+ }
+ if ( _group.checkDevicesCategory()==Tool::Category::Nb_Types ) {
+ QValueVector<QString> supported = _group.supportedDevices();
+ _devicesLabel->setText(i18n("Hardcoded (%1)").arg(supported.count()));
+ } else {
+ for (uint i=0; i<_devicesData.count(); i++) {
+ delete _devicesData[i].process;
+ _devicesData[i].process = checkDevicesProcess(i);
+ _devicesData[i].command = _devicesData[i].process->prettyCommand();
+ connect(_devicesData[i].process, SIGNAL(done(int)), SLOT(checkDevicesDone()));
+ connect(_devicesData[i].process, SIGNAL(timeout()), SLOT(checkDevicesDone()));
+ _devicesData[i].done = false;
+ _devicesData[i].checkLines.clear();
+ if ( !_devicesData[i].process->start(10000) ) _devicesLabel->setText(i18n("Failed"));
+ else _devicesLabel->setText(i18n("Detecting ..."));
+ }
+ }
+ FOR_EACH(Compile::DirectoryType, type) {
+ if ( _dirs[type]==0 || type==Compile::DirectoryType::Executable ) continue;
+ PURL::Directory execDir = _dirs[Compile::DirectoryType::Executable]->directory();
+ PURL::Directory dir = _group.autodetectDirectory(type, execDir, withWine());
+ if ( !dir.isEmpty() ) _dirs[type]->setDirectory(dir);
+ }
+ _dirty = false;
+}
+
+void ToolchainConfigWidget::showDetails()
+{
+ FOR_EACH(Tool::Category, k) {
+ if ( sender()!=_data[k].button ) continue;
+ QString s;
+ const Tool::Base *base = _group.base(k);
+ if ( base->checkExecutable() ) {
+ s += i18n("<qt><b>Command for executable detection:</b><br>%1<br>").arg(_data[k].command);
+ s += i18n("<b>Version string:</b><br>%1<br></qt>").arg(_data[k].checkLines.join("<br>"));
+ } else s += i18n("This tool cannot be automatically detected.");
+ MessageBox::text(s, Log::Show);
+ break;
+ }
+}
+
+void ToolchainConfigWidget::showDeviceDetails()
+{
+ QString s;
+ if ( _group.checkDevicesCategory()==Tool::Category::Nb_Types ) {
+ s += "<qt>";
+ QValueVector<QString> supported = _group.supportedDevices();
+ for (uint i=0; i<supported.count(); i++) {
+ if ( i!=0 ) {
+ if ( (i%10)==0 ) s += "<br>";
+ s += " ";
+ }
+ s += supported[i];
+ }
+ s += "</qt>";
+ } else {
+ uint nb = _group.nbCheckDevices();
+ for (uint i=0; i<nb; i++) {
+ if ( nb==1 ) s += i18n("<qt><b>Command for devices detection:</b><br>%1<br>").arg(_devicesData[i].command);
+ else s += i18n("<qt><b>Command #%1 for devices detection:</b><br>%2<br>").arg(i+1).arg(_devicesData[i].command);
+ QString ss = _devicesData[i].checkLines.join("<br>");
+ if ( nb==1 ) s += i18n("<b>Device string:</b><br>%1<br>").arg(ss);
+ else s += i18n("<b>Device string #%1:</b><br>%2<br>").arg(i+1).arg(ss);
+ }
+ }
+ MessageBox::text(s, Log::Show);
+}
diff --git a/src/tools/gui/toolchain_config_widget.h b/src/tools/gui/toolchain_config_widget.h
new file mode 100644
index 0000000..ad7978a
--- /dev/null
+++ b/src/tools/gui/toolchain_config_widget.h
@@ -0,0 +1,85 @@
+/***************************************************************************
+ * Copyright (C) 2005-2006 Nicolas Hadacek <hadacek@kde.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. *
+ ***************************************************************************/
+#ifndef TOOLCHAIN_CONFIG_WIDGET_H
+#define TOOLCHAIN_CONFIG_WIDGET_H
+
+#include <qwidgetstack.h>
+#include <qlabel.h>
+#include <klocale.h>
+#include <kpushbutton.h>
+
+#include "common/gui/key_gui.h"
+#include "common/global/process.h"
+#include "common/gui/config_widget.h"
+#include "tools/list/compile_process.h"
+class Container;
+namespace PURL { class DirectoryWidget; }
+namespace Tool { class Group; }
+
+//----------------------------------------------------------------------------
+class ToolchainConfigWidget : public ::ConfigWidget
+{
+ Q_OBJECT
+public:
+ ToolchainConfigWidget(const Tool::Group &group, QWidget *parent);
+ virtual ~ToolchainConfigWidget();
+ const Tool::Group &group() const { return _group; }
+ void init();
+
+public slots:
+ void detect();
+ void forceDetect();
+ virtual void loadConfig();
+ virtual void saveConfig();
+
+protected:
+ bool withWine() const;
+ Tool::OutputExecutableType outputType() const;
+ virtual void addCustomExecutableOptions(Container *) {}
+ virtual QString baseExecutable(Tool::Category category) const;
+ virtual ::Process::LineOutput *checkExecutableProcess(Tool::Category category) const;
+ virtual ::Process::LineOutput *checkDevicesProcess(uint i) const;
+
+protected slots:
+ void showDetails();
+ void showDeviceDetails();
+ void checkExecutableDone();
+ void checkDevicesDone();
+
+protected:
+ const Tool::Group &_group;
+ Compile::Config *_config;
+ bool _dirty;
+ QComboBox *_execType;
+ KeyComboBox<Tool::OutputExecutableType> *_outputType;
+ QLabel *_devicesLabel;
+ QMap<Compile::DirectoryType, PURL::DirectoryWidget *> _dirs;
+ class ExecData {
+ public:
+ ExecData() : label(0), button(0), process(0) {}
+ ~ExecData() { delete process; }
+ QLabel *label;
+ QString command;
+ QStringList checkLines;
+ KPushButton *button;
+ ::Process::LineOutput *process;
+ };
+ QMap<Tool::Category, ExecData> _data;
+ class DevicesData {
+ public:
+ DevicesData() : process(0) {}
+ bool done;
+ QString command;
+ QStringList checkLines;
+ ::Process::LineOutput *process;
+ };
+ QValueVector<DevicesData> _devicesData;
+};
+
+#endif