summaryrefslogtreecommitdiffstats
path: root/buildtools/custommakefiles/custommakeconfigwidget.cpp
blob: 10855e60902386a106faeeb96400ef2f7e77d8f3 (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
/***************************************************************************
 *   Copyright (C) 2003 by Hendrik Kueck                                   *
 *   kueck@cs.ubc.ca                                                       *
 *                                                                         *
 *   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 "custommakeconfigwidget.h"
#include <custombuildoptionswidgetbase.h>
#include <customprojectpart.h>
#include <tqcombobox.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqfileinfo.h>
#include <tqlabel.h>
#include <tqpushbutton.h>
#include <tqcheckbox.h>
#include <tqspinbox.h>
#include <tqlistview.h>
#include <tqgroupbox.h>
#include <tqvalidator.h>
#include <klineedit.h>
#include <kdebug.h>
#include <tdelocale.h>

#include <environmentvariableswidget.h>

CustomMakeConfigWidget::CustomMakeConfigWidget(CustomProjectPart* part, const TQString& configGroup, TQWidget* parent)
 : CustomMakeConfigWidgetBase(parent),
    m_part(part), m_configGroup(configGroup), m_dom( *part->projectDom() )
{
    abort_box->setChecked(DomUtil::readBoolEntry(m_dom, m_configGroup + "/make/abortonerror"));
    int numjobs = DomUtil::readIntEntry(m_dom, m_configGroup + "/make/numberofjobs");
    jobs_box->setValue(numjobs);
    runMultiJobs->setChecked( (numjobs > 0 ) );

    prio_box->setValue(DomUtil::readIntEntry(m_dom, m_configGroup + "/make/prio"));
    dontact_box->setChecked(DomUtil::readBoolEntry(m_dom, m_configGroup + "/make/dontact"));
    makebin_edit->setText(DomUtil::readEntry(m_dom, m_configGroup + "/make/makebin"));
    defaultTarget_edit->setText(DomUtil::readEntry(m_dom, m_configGroup + "/make/defaulttarget"));
    makeoptions_edit->setText(DomUtil::readEntry(m_dom, m_configGroup + "/make/makeoptions"));

    envs_combo->setValidator(new TQRegExpValidator(TQRegExp("^\\D[^\\s]*"), this));
    m_allEnvironments = m_part->allMakeEnvironments();
    m_currentEnvironment = m_part->currentMakeEnvironment();
    env_var_group->setColumnLayout( 1, TQt::Vertical );
    m_envWidget = new EnvironmentVariablesWidget(m_dom, m_configGroup + "/make/environments/" + m_currentEnvironment, env_var_group);
    envs_combo->insertStringList(m_allEnvironments);
    envs_combo->setEditText(m_currentEnvironment);
}


CustomMakeConfigWidget::~CustomMakeConfigWidget()
{

}

void CustomMakeConfigWidget::envNameChanged(const TQString& envName)
{
    TQStringList allEnvNames = m_part->allMakeEnvironments();
    bool canAdd = !allEnvNames.contains(envName) && !envName.contains("/") && !envName.isEmpty();
    bool canRemove = allEnvNames.contains(envName) && allEnvNames.count() > 1;
    addenvs_button->setEnabled(canAdd);
    copyenvs_button->setEnabled(canAdd);
    removeenvs_button->setEnabled(canRemove);
}

void CustomMakeConfigWidget::envChanged(const TQString& envName)
{
    if (envName == m_currentEnvironment || !m_allEnvironments.contains(envName))
        return;

    // save settings of previously active environment
    if (!m_currentEnvironment.isNull() )
        m_envWidget->accept();

    m_currentEnvironment = envName;
    m_envWidget->readEnvironment(m_dom, m_configGroup + "/make/environments/" + envName);
    envs_combo->setEditText(envName);
}

void CustomMakeConfigWidget::envAdded()
{
    TQString env = envs_combo->currentText();
    m_allEnvironments.append(env);

    envs_combo->clear();
    envs_combo->insertStringList(m_allEnvironments);
    envChanged(env);
}

void CustomMakeConfigWidget::envRemoved()
{
    TQString env = envs_combo->currentText();
    TQDomNode node = DomUtil::elementByPath(m_dom, m_configGroup + "/make/environments");
    node.removeChild(node.namedItem(env));
    m_allEnvironments.remove(env);
    envs_combo->clear();
    envs_combo->insertStringList(m_allEnvironments);
    m_currentEnvironment = TQString();
    envChanged( m_allEnvironments[0] );
}

void CustomMakeConfigWidget::envCopied()
{
    TQString env = envs_combo->currentText();
    m_allEnvironments.append(env);
    envs_combo->clear();
    envs_combo->insertStringList(m_allEnvironments);
    m_currentEnvironment = env;
    m_envWidget->changeConfigGroup(m_configGroup + "/make/environments/" + env);
    envs_combo->setEditText(env);
}

void CustomMakeConfigWidget::accept()
{
    DomUtil::writeBoolEntry(m_dom, m_configGroup + "/make/abortonerror", abort_box->isChecked());
    if( runMultiJobs->isChecked() )
        DomUtil::writeIntEntry(m_dom, m_configGroup + "/make/numberofjobs", jobs_box->value());
    else
        DomUtil::writeIntEntry(m_dom, m_configGroup + "/make/numberofjobs", 0);
    DomUtil::writeIntEntry(m_dom, m_configGroup + "/make/prio", prio_box->value());
    DomUtil::writeBoolEntry(m_dom, m_configGroup + "/make/dontact", dontact_box->isChecked());
    DomUtil::writeEntry(m_dom, m_configGroup + "/make/makebin", makebin_edit->text());
    DomUtil::writeEntry(m_dom, m_configGroup + "/make/defaulttarget", defaultTarget_edit->text());
    DomUtil::writeEntry(m_dom, m_configGroup + "/make/makeoptions", makeoptions_edit->text());
    DomUtil::writeEntry(m_dom, m_configGroup + "/make/selectedenvironment", m_currentEnvironment);
    m_envWidget->accept();
}

#include "custommakeconfigwidget.moc"