~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/lib/widgets/environmentvariableswidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2006-05-23 18:39:42 UTC
  • Revision ID: james.westby@ubuntu.com-20060523183942-hucifbvh68k2bwz7
Tags: upstream-3.3.2
Import upstream version 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2001-2002 Bernd Gehrmann <bernd@kdevelop.org>
 
3
   Copyright (C) 2003 John Firebaugh <jfirebaugh@kde.org>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.
 
19
*/
 
20
 
 
21
#include "environmentvariableswidget.h"
 
22
 
 
23
#include <qcheckbox.h>
 
24
#include <qlineedit.h>
 
25
#include <qspinbox.h>
 
26
#include <qlistview.h>
 
27
#include "domutil.h"
 
28
#include "addenvvardlg.h"
 
29
 
 
30
 
 
31
void EnvironmentVariablesWidget::addVarClicked()
 
32
{
 
33
    AddEnvvarDialog dlg( this, "add env dialog" ) ;
 
34
    if (QListViewItem *Item = listview->selectedItem())
 
35
    {
 
36
        dlg.setvarname(Item->text(0));
 
37
        dlg.setvalue(Item->text(1));
 
38
    }
 
39
    if (!dlg.exec())
 
40
        return;
 
41
 
 
42
    (void) new QListViewItem(listview, dlg.varname(), dlg.value());
 
43
}
 
44
 
 
45
 
 
46
void EnvironmentVariablesWidget::editVarClicked()
 
47
{
 
48
    AddEnvvarDialog dlg( this, "edit env dialog" );
 
49
    QListViewItem *item = listview->selectedItem();
 
50
    if (  !item )
 
51
        return;
 
52
    dlg.setvarname(item->text(0));
 
53
    dlg.setvalue(item->text(1));
 
54
    if (!dlg.exec())
 
55
        return;
 
56
 
 
57
    item->setText(0,dlg.varname());
 
58
    item->setText(1,dlg.value());
 
59
}
 
60
 
 
61
 
 
62
void EnvironmentVariablesWidget::removeVarClicked()
 
63
{
 
64
    delete listview->selectedItem();
 
65
}
 
66
 
 
67
 
 
68
EnvironmentVariablesWidget::EnvironmentVariablesWidget(QDomDocument &dom, const QString &configGroup,
 
69
                                   QWidget *parent, const char *name)
 
70
    : EnvironmentVariablesWidgetBase(parent, name),
 
71
      m_dom(dom), m_configGroup(configGroup)
 
72
{
 
73
    readEnvironment(dom, configGroup);
 
74
    connect( listview, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ), this, SLOT( editVarClicked() ) );
 
75
}
 
76
 
 
77
 
 
78
EnvironmentVariablesWidget::~EnvironmentVariablesWidget()
 
79
{}
 
80
 
 
81
void EnvironmentVariablesWidget::readEnvironment(QDomDocument &dom, const QString &configGroup)
 
82
{
 
83
    m_dom = dom;
 
84
    m_configGroup = configGroup;
 
85
 
 
86
    listview->clear();
 
87
 
 
88
    DomUtil::PairList list =
 
89
        DomUtil::readPairListEntry(dom, m_configGroup, "envvar", "name", "value");
 
90
 
 
91
    QListViewItem *lastItem = 0;
 
92
 
 
93
    DomUtil::PairList::ConstIterator it;
 
94
    for (it = list.begin(); it != list.end(); ++it) {
 
95
        QListViewItem *newItem = new QListViewItem(listview, (*it).first, (*it).second);
 
96
        if (lastItem)
 
97
            newItem->moveItem(lastItem);
 
98
        lastItem = newItem;
 
99
    }
 
100
}
 
101
 
 
102
void EnvironmentVariablesWidget::changeConfigGroup( const QString &configGroup)
 
103
{
 
104
    m_configGroup = configGroup;
 
105
}
 
106
 
 
107
void EnvironmentVariablesWidget::accept()
 
108
{
 
109
    DomUtil::PairList list;
 
110
    QListViewItem *item = listview->firstChild();
 
111
    while (item) {
 
112
        list << DomUtil::Pair(item->text(0), item->text(1));
 
113
        item = item->nextSibling();
 
114
    }
 
115
 
 
116
    DomUtil::writePairListEntry(m_dom, m_configGroup, "envvar", "name", "value", list);
 
117
}
 
118
 
 
119
#include "environmentvariableswidget.moc"