summaryrefslogtreecommitdiffstats
path: root/src/tools/gui/toolchain_config_center.cpp
blob: 36859978936b24a7bb7ea51301ac8e035284a84e (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
/***************************************************************************
 *   Copyright (C) 2005-2007 Nicolas Hadacek <[email protected]>             *
 *   Copyright (C) 2004 Alain Gibaud <[email protected]>                *
 *                                                                         *
 *   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 <tqlabel.h>
#include <tqlayout.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, TQWidget *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(TQString(), "viewmag"), _frame);
  connect(_infoButton, TQ_SIGNAL(clicked()), TQ_SLOT(showInformationDialog()));
  _titleBox->addWidget(_infoButton);

  TQWidget *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;
      TQStringList names = family.label();
      names += it.data()->label();
      TQWidget *page = addPage(names);
      TQVBoxLayout *vbox = new TQVBoxLayout(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, TQ_SIGNAL(aboutToShowPage(TQWidget *)), TQ_SLOT(aboutToShowPageSlot(TQWidget *)));
}

void ToolchainsConfigCenter::aboutToShowPageSlot(TQWidget *page)
{
  if ( !_pages.contains(page) ) _infoButton->hide();
  else {
    _infoButton->show();
    TQTimer::singleShot(0, _pages[page], TQ_SLOT(detect()));
  }
}

void ToolchainsConfigCenter::slotApply()
{
  TQMap<TQWidget *, 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;
  TQMap<TQWidget *, 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();
}