summaryrefslogtreecommitdiffstats
path: root/src/tools/list/tools_config_widget.cpp
blob: a6b853ae88246df6ca8bcebdcae002d7b70e1b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/***************************************************************************
 *   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 "tools_config_widget.h"

#include <tqwidgetstack.h>
#include <tqlabel.h>

#include "tool_list.h"
#include "tools/gui/tool_config_widget.h"
#include "tools/gui/tool_group_ui.h"
#include "compile_config.h"
#include "compile_process.h"
#include "libgui/project.h"

//----------------------------------------------------------------------------
HelpDialog::HelpDialog(TQWidget *parent)
  : Dialog(parent, "help_dialog", false, i18n("Help Dialog"), Close, Close, false)
{
  TQGridLayout *top = new TQGridLayout(mainWidget(), 1, 1, 10, 10);
  uint k = 0;
  for (; Compile::ARGUMENT_DATA[k].key; k++) {
    TQLabel *label = new TQLabel(Compile::ARGUMENT_DATA[k].key, mainWidget());
    top->addWidget(label, k, 0);
    label = new TQLabel(i18n(Compile::ARGUMENT_DATA[k].description), mainWidget());
    top->addWidget(label, k, 1);
  }
  top->setColStretch(2, 1);
  top->setRowStretch(k, 1);
}

//----------------------------------------------------------------------------
ToolsConfigWidget::ToolsConfigWidget(Project *project, TQWidget *parent)
  : ::ConfigWidget(parent), _project(project), _helpDialog(0)
{
  uint row = 0;

  TQLabel *label = new TQLabel(i18n("Toolchain:"), this);
  addWidget(label, row,row, 0,0);
  _tool = new KeyComboBox<TQString>(this);
  Tool::Lister::ConstIterator it;
  for (it=Tool::lister().begin(); it!=Tool::lister().end(); ++it)
    _tool->appendItem(it.key(), it.data()->label());
  connect(_tool->widget(), TQ_SIGNAL(activated(int)), TQ_SLOT(toolChanged()));
  addWidget(_tool->widget(), row,row, 1,1);
  label = new TQLabel(i18n("Output type:"), this);
  addWidget(label, row,row, 2,2);
  _output = new KeyComboBox<Tool::OutputType>(this);
  FOR_EACH(Tool::OutputType, type) _output->appendItem(type, type.label());
  addWidget(_output->widget(), row,row, 3,3);
  row++;

  _mainStack = new TQWidgetStack(this);
  addWidget(_mainStack, row,row, 0,4);
  row++;
  _tabWidget = new TQTabWidget(_mainStack);
  _mainStack->addWidget(_tabWidget);
  FOR_EACH(Tool::Category, category) {
    _stacks[category] = new KeyWidgetStack<TQString>(_tabWidget);
    _stacks[category]->widget()->setMargin(10);
    Tool::Lister::ConstIterator it;
    for (it=Tool::lister().begin(); it!=Tool::lister().end(); ++it) {
      if ( it.data()->isCustom() ) continue;
      if ( !it.data()->needs(_project, category) ) continue;
      ToolConfigWidget *cw = static_cast<const Tool::GroupUI *>(it.data()->gui())->createConfigWidget(category, project);
      Q_ASSERT(cw);
      _stacks[category]->appendItem(it.key(), cw);
      connect(cw, TQ_SIGNAL(displayHelp()), TQ_SLOT(displayHelp()));
    }
  }
  _customWidget = new TQWidget(_mainStack);
  _mainStack->addWidget(_customWidget);
  TQVBoxLayout *vbox = new TQVBoxLayout(_customWidget);
  label = new TQLabel(i18n("Custom shell commands:"), _customWidget);
  vbox->addWidget(label);
  _commandsEditor = new EditListBox(1, _customWidget, "command_editor", EditListBox::DuplicatesAllowed);
  vbox->addWidget(_commandsEditor);

  setColStretch(4, 1);
}

void ToolsConfigWidget::toolChanged()
{
  TQString name = _tool->currentItem();
  bool canMakeLibrary = Tool::lister().group(name)->needs(_project, Tool::Category::Librarian);
  _output->widget()->setEnabled(canMakeLibrary);
  if ( !canMakeLibrary ) _output->setCurrentItem(Tool::OutputType::Executable);
  if ( name==Tool::Group::CUSTOM_NAME ) _mainStack->raiseWidget(_customWidget);
  else {
    _mainStack->raiseWidget(_tabWidget);
    FOR_EACH(Tool::Category, k) {
      _tabWidget->removePage(_stacks[k]->widget());
      _stacks[k]->widget()->hide();
      if ( _stacks[k]->contains(name) ) {
        _stacks[k]->setCurrentItem(name);
        _stacks[k]->widget()->show();
        _tabWidget->addTab(_stacks[k]->widget(), i18n(k.data().title));
      }
    }
    _tabWidget->setCurrentPage(0);
  }
}

void ToolsConfigWidget::loadConfig()
{
  const Tool::Group &group = Compile::Config::toolGroup(_project);
  _tool->setCurrentItem(group.name());
  _output->setCurrentItem(_project->outputType());
  TQStringList commands = Compile::Config::customCommands(_project);
  _commandsEditor->setTexts(commands);
  toolChanged();
  FOR_EACH(Tool::Category, k) {
    KeyWidgetStack<TQString>::ConstIterator it;
    for (it=_stacks[k]->begin(); it!=_stacks[k]->end(); ++it) {
      if ( it.key()==Tool::Group::CUSTOM_NAME ) continue;
      static_cast<ToolConfigWidget *>(_stacks[k]->item(it.key()))->loadConfig();
    }
  }
}

void ToolsConfigWidget::saveConfig()
{
  TQString name = _tool->currentItem();
  Compile::Config::setToolGroup(_project, *Tool::lister().group(name));
  _project->setOutputType(_output->currentItem());
  Compile::Config::setCustomCommands(_project, _commandsEditor->texts());
  FOR_EACH(Tool::Category, k) {
    if ( !_stacks[k]->contains(name) ) continue;
    TQWidget *w = _stacks[k]->item(name);
    static_cast<ToolConfigWidget *>(w)->saveConfig();
  }
}

void ToolsConfigWidget::displayHelp()
{
  if ( _helpDialog.isNull() ) _helpDialog = new HelpDialog(this);
  _helpDialog->show();
}