From 3c1824f39867bc2ada45fe32785267caa5dfb04b Mon Sep 17 00:00:00 2001 From: wazlaf Date: Wed, 30 Oct 2002 20:30:08 +0000 Subject: Console configuration widget done, Environment variables can now be set --- (limited to 'noncore/apps/opie-console/consoleconfigwidget.cpp') diff --git a/noncore/apps/opie-console/consoleconfigwidget.cpp b/noncore/apps/opie-console/consoleconfigwidget.cpp new file mode 100644 index 0000000..70e2e78 --- a/dev/null +++ b/noncore/apps/opie-console/consoleconfigwidget.cpp @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "consoleconfigwidget.h" + +ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent, + const char* na ) + : ProfileDialogConnectionWidget( name, parent, na ) { + m_lay = new QVBoxLayout( this ); + QLabel *label = new QLabel(tr("Command to execute"), this); + m_lay->addWidget(label); + m_cmd = new QLineEdit(this); + m_lay->addWidget(m_cmd); + label = new QLabel(tr("Environment Variables"), this); + m_lay->addWidget(label); + m_env = new QListView(this); + m_env->addColumn(tr("Name")); + m_env->addColumn(tr("Value")); + m_lay->addWidget(m_env); + + QHBox *hbox = new QHBox(this); + label = new QLabel(tr("Name :"), hbox); + m_name = new QLineEdit(hbox); + m_lay->addWidget(hbox); + + hbox = new QHBox(this); + label = new QLabel(tr("Value :"), hbox); + m_value = new QLineEdit(hbox); + m_lay->addWidget(hbox); + + hbox = new QHBox(this); + hbox->setSpacing(10); + m_remove = new QPushButton(tr("Remove"), hbox); + connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove())); + m_add = new QPushButton(tr("Add"), hbox); + connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd())); + m_lay->addWidget(hbox); +} + +void ConsoleConfigWidget::slotAdd() { + if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) { + QListViewItem *item = new QListViewItem(m_env); + item->setText(0, m_name->text()); + item->setText(1, m_value->text()); + m_env->insertItem(item); + } +} + +void ConsoleConfigWidget::slotRemove() { + QListViewItem *item = m_env->currentItem(); + if (item) { + m_env->takeItem(item); + } +} + +ConsoleConfigWidget::~ConsoleConfigWidget() { +} + +void ConsoleConfigWidget::load( const Profile& prof ) { + m_cmd->setText(prof.readEntry("Command", "/bin/bash")); + int envcount = prof.readNumEntry("EnvVars", 0); + for (int i=0; isetText(0, name); + item->setText(1, value); + m_env->insertItem(item); + } + } +} + +void ConsoleConfigWidget::save( Profile& prof ) { + prof.writeEntry( "Command", m_cmd->text()); + QListViewItem *item = m_env->firstChild(); + int counter = 0; + while (item) { + QString name = item->text(0); + QString value = item->text(1); + prof.writeEntry("Env_Name_" + QString::number(counter), name); + prof.writeEntry("Env_Value_" + QString::number(counter), value); + item = item->nextSibling(); + counter++; + } + prof.writeEntry("EnvVars", QString::number(counter)); +} + -- cgit v0.9.0.2