KDevelop API Documentation

environmentvariableswidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 2001-2002 Bernd Gehrmann <bernd@kdevelop.org>
00003    Copyright (C) 2003 John Firebaugh <jfirebaugh@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018    Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include "environmentvariableswidget.h"
00022 
00023 #include <qcheckbox.h>
00024 #include <qlineedit.h>
00025 #include <qspinbox.h>
00026 #include <qlistview.h>
00027 #include "domutil.h"
00028 #include "addenvvardlg.h"
00029 
00030 
00031 void EnvironmentVariablesWidget::addVarClicked()
00032 {
00033     AddEnvvarDialog dlg;
00034     if (QListViewItem *Item = listview->selectedItem())
00035     {
00036         dlg.setvarname(Item->text(0));
00037         dlg.setvalue(Item->text(1));
00038     }
00039     if (!dlg.exec())
00040         return;
00041 
00042     (void) new QListViewItem(listview, dlg.varname(), dlg.value());
00043 }
00044 
00045 
00046 void EnvironmentVariablesWidget::editVarClicked()
00047 {
00048     AddEnvvarDialog dlg;
00049     QListViewItem *item = listview->selectedItem();
00050     if (  !item )
00051         return;
00052     dlg.setvarname(item->text(0));
00053     dlg.setvalue(item->text(1));
00054     if (!dlg.exec())
00055         return;
00056 
00057     item->setText(0,dlg.varname());
00058     item->setText(1,dlg.value());
00059 }
00060 
00061 
00062 void EnvironmentVariablesWidget::removeVarClicked()
00063 {
00064     delete listview->selectedItem();
00065 }
00066 
00067 
00068 EnvironmentVariablesWidget::EnvironmentVariablesWidget(QDomDocument &dom, const QString &configGroup,
00069                                    QWidget *parent, const char *name)
00070     : EnvironmentVariablesWidgetBase(parent, name),
00071       m_dom(dom), m_configGroup(configGroup)
00072 {
00073     readEnvironment(dom, configGroup);
00074     connect( listview, SIGNAL( doubleClicked ( QListViewItem *, const QPoint &, int ) ), this, SLOT( editVarClicked() ) );
00075 }
00076 
00077 
00078 EnvironmentVariablesWidget::~EnvironmentVariablesWidget()
00079 {}
00080 
00081 void EnvironmentVariablesWidget::readEnvironment(QDomDocument &dom, const QString &configGroup)
00082 {
00083     m_dom = dom;
00084     m_configGroup = configGroup;
00085 
00086     listview->clear();
00087 
00088     DomUtil::PairList list =
00089         DomUtil::readPairListEntry(dom, m_configGroup, "envvar", "name", "value");
00090 
00091     QListViewItem *lastItem = 0;
00092 
00093     DomUtil::PairList::ConstIterator it;
00094     for (it = list.begin(); it != list.end(); ++it) {
00095         QListViewItem *newItem = new QListViewItem(listview, (*it).first, (*it).second);
00096         if (lastItem)
00097             newItem->moveItem(lastItem);
00098         lastItem = newItem;
00099     }
00100 }
00101 
00102 void EnvironmentVariablesWidget::changeConfigGroup( const QString &configGroup)
00103 {
00104     m_configGroup = configGroup;
00105 }
00106 
00107 void EnvironmentVariablesWidget::accept()
00108 {
00109     DomUtil::PairList list;
00110     QListViewItem *item = listview->firstChild();
00111     while (item) {
00112         list << DomUtil::Pair(item->text(0), item->text(1));
00113         item = item->nextSibling();
00114     }
00115 
00116     DomUtil::writePairListEntry(m_dom, m_configGroup, "envvar", "name", "value", list);
00117 }
00118 
00119 #include "environmentvariableswidget.moc"
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 23 00:03:52 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003