summaryrefslogtreecommitdiffstats
path: root/buildtools/lib/widgets/environmentvariableswidget.cpp
blob: cf06d012d9efbb2b1be1b5eb6bfc08f3bed3ec87 (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
/* This file is part of the KDE project
   Copyright (C) 2001-2002 Bernd Gehrmann <[email protected]>
   Copyright (C) 2003 John Firebaugh <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "environmentvariableswidget.h"
#include "environmentdisplaydialog.h"

#include <tqcheckbox.h>
#include <tqlineedit.h>
#include <tqspinbox.h>
#include <tqlistview.h>
#include "domutil.h"
#include "addenvvardlg.h"


void EnvironmentVariablesWidget::addVarClicked()
{
    AddEnvvarDialog dlg( this, "add env dialog" ) ;
    if (TQListViewItem *Item = listview->selectedItem())
    {
        dlg.setvarname(Item->text(0));
        dlg.setvalue(Item->text(1));
    }
    if (!dlg.exec())
        return;

    (void) new TQListViewItem(listview, dlg.varname(), dlg.value());
}


void EnvironmentVariablesWidget::editVarClicked()
{
    AddEnvvarDialog dlg( this, "edit env dialog" );
    TQListViewItem *item = listview->selectedItem();
    if (  !item )
        return;
    dlg.setvarname(item->text(0));
    dlg.setvalue(item->text(1));
    if (!dlg.exec())
        return;

    item->setText(0,dlg.varname());
    item->setText(1,dlg.value());
}


void EnvironmentVariablesWidget::removeVarClicked()
{
    delete listview->selectedItem();
}


EnvironmentVariablesWidget::EnvironmentVariablesWidget(TQDomDocument &dom, const TQString &configGroup,
                                   TQWidget *parent, const char *name)
    : EnvironmentVariablesWidgetBase(parent, name),
      m_dom(dom), m_configGroup(configGroup)
{
    readEnvironment(dom, configGroup);
    connect( listview, TQ_SIGNAL( doubleClicked ( TQListViewItem *, const TQPoint &, int ) ), this, TQ_SLOT( editVarClicked() ) );
}


EnvironmentVariablesWidget::~EnvironmentVariablesWidget()
{}

void EnvironmentVariablesWidget::readEnvironment(TQDomDocument &dom, const TQString &configGroup)
{
    m_dom = dom;
    m_configGroup = configGroup;

    listview->clear();

    DomUtil::PairList list =
        DomUtil::readPairListEntry(dom, m_configGroup, "envvar", "name", "value");

    TQListViewItem *lastItem = 0;

    DomUtil::PairList::ConstIterator it;
    for (it = list.begin(); it != list.end(); ++it) {
        TQListViewItem *newItem = new TQListViewItem(listview, (*it).first, (*it).second);
        if (lastItem)
            newItem->moveItem(lastItem);
        lastItem = newItem;
    }
}

void EnvironmentVariablesWidget::changeConfigGroup( const TQString &configGroup)
{
    m_configGroup = configGroup;
}

void EnvironmentVariablesWidget::accept()
{
    DomUtil::PairList list;
    TQListViewItem *item = listview->firstChild();
    while (item) {
        list << DomUtil::Pair(item->text(0), item->text(1));
        item = item->nextSibling();
    }

    DomUtil::writePairListEntry(m_dom, m_configGroup, "envvar", "name", "value", list);
}

void EnvironmentVariablesWidget::environmentClicked()
{
    EnvironmentDisplayDialog dlg;
    dlg.exec();
}

#include "environmentvariableswidget.moc"