Diffstat (limited to 'noncore/apps/opie-console/consoleconfigwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/consoleconfigwidget.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
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 @@ | |||
1 | #include <qlabel.h> | ||
2 | #include <qlayout.h> | ||
3 | #include <qcombobox.h> | ||
4 | #include <qlineedit.h> | ||
5 | #include <qpushbutton.h> | ||
6 | #include <qlistview.h> | ||
7 | #include <qhbox.h> | ||
8 | #include <qregexp.h> | ||
9 | #include <stdio.h> | ||
10 | |||
11 | #include "consoleconfigwidget.h" | ||
12 | |||
13 | ConsoleConfigWidget::ConsoleConfigWidget( const QString& name, QWidget* parent, | ||
14 | const char* na ) | ||
15 | : ProfileDialogConnectionWidget( name, parent, na ) { | ||
16 | m_lay = new QVBoxLayout( this ); | ||
17 | QLabel *label = new QLabel(tr("Command to execute"), this); | ||
18 | m_lay->addWidget(label); | ||
19 | m_cmd = new QLineEdit(this); | ||
20 | m_lay->addWidget(m_cmd); | ||
21 | label = new QLabel(tr("Environment Variables"), this); | ||
22 | m_lay->addWidget(label); | ||
23 | m_env = new QListView(this); | ||
24 | m_env->addColumn(tr("Name")); | ||
25 | m_env->addColumn(tr("Value")); | ||
26 | m_lay->addWidget(m_env); | ||
27 | |||
28 | QHBox *hbox = new QHBox(this); | ||
29 | label = new QLabel(tr("Name :"), hbox); | ||
30 | m_name = new QLineEdit(hbox); | ||
31 | m_lay->addWidget(hbox); | ||
32 | |||
33 | hbox = new QHBox(this); | ||
34 | label = new QLabel(tr("Value :"), hbox); | ||
35 | m_value = new QLineEdit(hbox); | ||
36 | m_lay->addWidget(hbox); | ||
37 | |||
38 | hbox = new QHBox(this); | ||
39 | hbox->setSpacing(10); | ||
40 | m_remove = new QPushButton(tr("Remove"), hbox); | ||
41 | connect(m_remove, SIGNAL(clicked()), this, SLOT(slotRemove())); | ||
42 | m_add = new QPushButton(tr("Add"), hbox); | ||
43 | connect(m_add, SIGNAL(clicked()), this, SLOT(slotAdd())); | ||
44 | m_lay->addWidget(hbox); | ||
45 | } | ||
46 | |||
47 | void ConsoleConfigWidget::slotAdd() { | ||
48 | if (!(m_name->text().isEmpty() || m_value->text().isEmpty())) { | ||
49 | QListViewItem *item = new QListViewItem(m_env); | ||
50 | item->setText(0, m_name->text()); | ||
51 | item->setText(1, m_value->text()); | ||
52 | m_env->insertItem(item); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void ConsoleConfigWidget::slotRemove() { | ||
57 | QListViewItem *item = m_env->currentItem(); | ||
58 | if (item) { | ||
59 | m_env->takeItem(item); | ||
60 | } | ||
61 | } | ||
62 | |||
63 | ConsoleConfigWidget::~ConsoleConfigWidget() { | ||
64 | } | ||
65 | |||
66 | void ConsoleConfigWidget::load( const Profile& prof ) { | ||
67 | m_cmd->setText(prof.readEntry("Command", "/bin/bash")); | ||
68 | int envcount = prof.readNumEntry("EnvVars", 0); | ||
69 | for (int i=0; i<envcount; i++) { | ||
70 | QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); | ||
71 | QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); | ||
72 | if (!(name.isEmpty() || value.isEmpty())) { | ||
73 | QListViewItem *item = new QListViewItem(m_env); | ||
74 | item->setText(0, name); | ||
75 | item->setText(1, value); | ||
76 | m_env->insertItem(item); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | void ConsoleConfigWidget::save( Profile& prof ) { | ||
82 | prof.writeEntry( "Command", m_cmd->text()); | ||
83 | QListViewItem *item = m_env->firstChild(); | ||
84 | int counter = 0; | ||
85 | while (item) { | ||
86 | QString name = item->text(0); | ||
87 | QString value = item->text(1); | ||
88 | prof.writeEntry("Env_Name_" + QString::number(counter), name); | ||
89 | prof.writeEntry("Env_Value_" + QString::number(counter), value); | ||
90 | item = item->nextSibling(); | ||
91 | counter++; | ||
92 | } | ||
93 | prof.writeEntry("EnvVars", QString::number(counter)); | ||
94 | } | ||
95 | |||