author | wazlaf <wazlaf> | 2002-10-30 20:30:08 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-10-30 20:30:08 (UTC) |
commit | 3c1824f39867bc2ada45fe32785267caa5dfb04b (patch) (unidiff) | |
tree | 08a6e7872f5d100cac7c1adb983e44f6b145af2f | |
parent | 9af1c14974a2131505b82441bfb0bf0475bb2cc9 (diff) | |
download | opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.zip opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.tar.gz opie-3c1824f39867bc2ada45fe32785267caa5dfb04b.tar.bz2 |
Console configuration widget done, Environment variables can now be set
-rw-r--r-- | noncore/apps/opie-console/MyPty.cpp | 27 | ||||
-rw-r--r-- | noncore/apps/opie-console/MyPty.h | 6 | ||||
-rw-r--r-- | noncore/apps/opie-console/PLANS | 2 | ||||
-rw-r--r-- | noncore/apps/opie-console/consoleconfigwidget.cpp | 95 | ||||
-rw-r--r-- | noncore/apps/opie-console/consoleconfigwidget.h | 34 | ||||
-rw-r--r-- | noncore/apps/opie-console/default.cpp | 9 | ||||
-rw-r--r-- | noncore/apps/opie-console/opie-console.pro | 6 |
7 files changed, 162 insertions, 17 deletions
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp index 534f79a..b0f0275 100644 --- a/noncore/apps/opie-console/MyPty.cpp +++ b/noncore/apps/opie-console/MyPty.cpp | |||
@@ -142,14 +142,8 @@ void MyPty::error() | |||
142 | } | 142 | } |
143 | 143 | ||
144 | void MyPty::start() { | 144 | void MyPty::start() { |
145 | char* cmd = "/bin/sh"; | ||
146 | |||
147 | if ( QFile::exists( "/bin/bash" ) ) { | ||
148 | cmd = "/bin/bash"; | ||
149 | } | ||
150 | |||
151 | QStrList lis; | 145 | QStrList lis; |
152 | int r =run(cmd, lis, 0, 0); | 146 | int r =run(m_cmd.latin1(), lis, 0, 0); |
153 | r = r; | 147 | r = r; |
154 | } | 148 | } |
155 | /*! | 149 | /*! |
@@ -182,7 +176,10 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int) | |||
182 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); | 176 | tcsetattr( STDIN_FILENO, TCSANOW, &ttmode ); |
183 | setenv("TERM",m_term,1); | 177 | setenv("TERM",m_term,1); |
184 | setenv("COLORTERM","0",1); | 178 | setenv("COLORTERM","0",1); |
185 | 179 | EnvironmentMap::Iterator it; | |
180 | for (it = m_env.begin(); it != m_env.end(); it++) { | ||
181 | setenv(it.key().latin1(), it.data().latin1(), 1); | ||
182 | } | ||
186 | if (getuid() == 0) { | 183 | if (getuid() == 0) { |
187 | char msg[] = "WARNING: You are running this shell as root!\n"; | 184 | char msg[] = "WARNING: You are running this shell as root!\n"; |
188 | write(ttyfd, msg, sizeof(msg)); | 185 | write(ttyfd, msg, sizeof(msg)); |
@@ -263,6 +260,7 @@ MyPty::MyPty(const Profile& prof) : m_cpid(0) | |||
263 | m_fd = openPty(); | 260 | m_fd = openPty(); |
264 | ProcCtl* ctl = ProcCtl::self(); | 261 | ProcCtl* ctl = ProcCtl::self(); |
265 | Q_UNUSED(ctl); | 262 | Q_UNUSED(ctl); |
263 | reload(prof); | ||
266 | } | 264 | } |
267 | 265 | ||
268 | /*! | 266 | /*! |
@@ -291,8 +289,17 @@ void MyPty::close() { | |||
291 | donePty(); | 289 | donePty(); |
292 | m_fd = openPty(); | 290 | m_fd = openPty(); |
293 | } | 291 | } |
294 | void MyPty::reload( const Profile& ) { | 292 | void MyPty::reload( const Profile& prof) { |
295 | 293 | m_env.clear(); | |
294 | m_cmd = prof.readEntry("Command", "/bin/bash"); | ||
295 | int envcount = prof.readNumEntry("EnvVars", 0); | ||
296 | for (int i=0; i<envcount; i++) { | ||
297 | QString name = prof.readEntry("Env_Name_" + QString::number(i), ""); | ||
298 | QString value = prof.readEntry("Env_Value_" + QString::number(i), ""); | ||
299 | if (!(name.isEmpty() || value.isEmpty())) { | ||
300 | m_env.insert(name, value); | ||
301 | } | ||
302 | } | ||
296 | } | 303 | } |
297 | /*! sends len bytes through the line */ | 304 | /*! sends len bytes through the line */ |
298 | void MyPty::send(const QByteArray& ar) | 305 | void MyPty::send(const QByteArray& ar) |
diff --git a/noncore/apps/opie-console/MyPty.h b/noncore/apps/opie-console/MyPty.h index 7561ca3..b292ce4 100644 --- a/noncore/apps/opie-console/MyPty.h +++ b/noncore/apps/opie-console/MyPty.h | |||
@@ -23,10 +23,13 @@ | |||
23 | #define MY_PTY_H | 23 | #define MY_PTY_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qlist.h> | ||
26 | #include <qstrlist.h> | 27 | #include <qstrlist.h> |
27 | 28 | ||
28 | #include "io_layer.h" | 29 | #include "io_layer.h" |
29 | 30 | ||
31 | typedef QMap<QString, QString> EnvironmentMap; | ||
32 | |||
30 | class Profile; | 33 | class Profile; |
31 | class QSocketNotifier; | 34 | class QSocketNotifier; |
32 | class MyPty : public IOLayer | 35 | class MyPty : public IOLayer |
@@ -95,6 +98,9 @@ private: | |||
95 | QSocketNotifier* m_sn_e; | 98 | QSocketNotifier* m_sn_e; |
96 | QSocketNotifier* m_sn_r; | 99 | QSocketNotifier* m_sn_r; |
97 | char* m_term; | 100 | char* m_term; |
101 | |||
102 | QString m_cmd; | ||
103 | EnvironmentMap m_env; | ||
98 | }; | 104 | }; |
99 | 105 | ||
100 | #endif | 106 | #endif |
diff --git a/noncore/apps/opie-console/PLANS b/noncore/apps/opie-console/PLANS index 8e0bee4..a7c7578 100644 --- a/noncore/apps/opie-console/PLANS +++ b/noncore/apps/opie-console/PLANS | |||
@@ -27,10 +27,10 @@ keyboard? | |||
27 | Fullscreen | 27 | Fullscreen |
28 | Modem - Josef | 28 | Modem - Josef |
29 | Keys - hash | 29 | Keys - hash |
30 | Scripting - wazlaf | ||
30 | 31 | ||
31 | TASKS in progress: | 32 | TASKS in progress: |
32 | Keys - hash | 33 | Keys - hash |
33 | Scripting - wazlaf | ||
34 | 34 | ||
35 | Session->Profile - hash => why is this needed? you can not change any settings | 35 | Session->Profile - hash => why is this needed? you can not change any settings |
36 | after you start the session, so all you would do is | 36 | after you start the session, so all you would do is |
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 | |||
diff --git a/noncore/apps/opie-console/consoleconfigwidget.h b/noncore/apps/opie-console/consoleconfigwidget.h new file mode 100644 index 0000000..c980cb4 --- a/dev/null +++ b/noncore/apps/opie-console/consoleconfigwidget.h | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef OPIE_CONSOLE_CONFIG_WIDGET_H | ||
2 | #define OPIE_CONSOLE_CONFIG_WIDGET_H | ||
3 | |||
4 | #include "profiledialogwidget.h" | ||
5 | |||
6 | class QVBoxLayout; | ||
7 | class QLineEdit; | ||
8 | class QListView; | ||
9 | class QPushButton; | ||
10 | |||
11 | class ConsoleConfigWidget : public ProfileDialogConnectionWidget { | ||
12 | Q_OBJECT | ||
13 | public: | ||
14 | ConsoleConfigWidget( const QString& name, QWidget* parent, const char* name = 0l ); | ||
15 | ~ConsoleConfigWidget(); | ||
16 | |||
17 | void load( const Profile& ); | ||
18 | void save( Profile& ); | ||
19 | |||
20 | protected slots: | ||
21 | void slotAdd(); | ||
22 | void slotRemove(); | ||
23 | private: | ||
24 | QVBoxLayout *m_lay; | ||
25 | QLineEdit *m_cmd; | ||
26 | QLineEdit *m_name; | ||
27 | QLineEdit *m_value; | ||
28 | QListView *m_env; | ||
29 | QPushButton *m_add; | ||
30 | QPushButton *m_remove; | ||
31 | }; | ||
32 | |||
33 | |||
34 | #endif | ||
diff --git a/noncore/apps/opie-console/default.cpp b/noncore/apps/opie-console/default.cpp index 5d82c6a..b060139 100644 --- a/noncore/apps/opie-console/default.cpp +++ b/noncore/apps/opie-console/default.cpp | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "modemconfigwidget.h" | 10 | #include "modemconfigwidget.h" |
11 | #include "terminalwidget.h" | 11 | #include "terminalwidget.h" |
12 | #include "function_keyboard.h" | 12 | #include "function_keyboard.h" |
13 | #include "consoleconfigwidget.h" | ||
13 | #include "MyPty.h" | 14 | #include "MyPty.h" |
14 | 15 | ||
15 | #include "default.h" | 16 | #include "default.h" |
@@ -67,8 +68,8 @@ extern "C" { | |||
67 | ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { | 68 | ProfileDialogWidget* newBTWidget( const QString& str, QWidget* wid ) { |
68 | return new BTConfigWidget(str, wid ); | 69 | return new BTConfigWidget(str, wid ); |
69 | } | 70 | } |
70 | ProfileDialogWidget* newConsoleWid( const QString& , QWidget* ) { | 71 | ProfileDialogWidget* newConsoleWid( const QString& str, QWidget* wid ) { |
71 | return 0l; | 72 | return new ConsoleConfigWidget(str, wid ); |
72 | } | 73 | } |
73 | 74 | ||
74 | 75 | ||
@@ -102,13 +103,13 @@ Default::Default( MetaFactory* fact ) { | |||
102 | // fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); | 103 | // fact->addIOLayerFactory( "irda", QObject::tr("Infrared"), newIrDaLayer ); |
103 | // fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); | 104 | // fact->addIOLayerFactory( "bt", QObject::tr("Bluetooth"), newBTLayer ); |
104 | fact->addIOLayerFactory( "modem", QObject::tr("Modem"), newModemLayer ); | 105 | fact->addIOLayerFactory( "modem", QObject::tr("Modem"), newModemLayer ); |
105 | fact->addIOLayerFactory( "console", QObject::tr("local Console"), newConsole ); | 106 | fact->addIOLayerFactory( "console", QObject::tr("Local Console"), newConsole ); |
106 | 107 | ||
107 | fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); | 108 | fact->addConnectionWidgetFactory( "serial", QObject::tr("Serial"), newSerialWidget ); |
108 | // fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); | 109 | // fact->addConnectionWidgetFactory( "irda", QObject::tr("Infrared"), newIrDaWidget ); |
109 | fact->addConnectionWidgetFactory( "modem", QObject::tr("Modem"), newModemWidget ); | 110 | fact->addConnectionWidgetFactory( "modem", QObject::tr("Modem"), newModemWidget ); |
110 | // fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); | 111 | // fact->addConnectionWidgetFactory( "bt", QObject::tr("Bluetooth"), newBTWidget ); |
111 | fact->addConnectionWidgetFactory( "console", QObject::tr("local Console"), newConsoleWid ); | 112 | fact->addConnectionWidgetFactory( "console", QObject::tr("Local Console"), newConsoleWid ); |
112 | 113 | ||
113 | fact->addTerminalWidgetFactory( "default", QObject::tr("Default Terminal"), newTerminalWidget ); | 114 | fact->addTerminalWidgetFactory( "default", QObject::tr("Default Terminal"), newTerminalWidget ); |
114 | fact->addKeyboardWidgetFactory( "defaultKeys", QObject::tr("Default Keyboard"), | 115 | fact->addKeyboardWidgetFactory( "defaultKeys", QObject::tr("Default Keyboard"), |
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro index f5737d4..e3f92f0 100644 --- a/noncore/apps/opie-console/opie-console.pro +++ b/noncore/apps/opie-console/opie-console.pro | |||
@@ -30,7 +30,8 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h io_modem.h \ | |||
30 | terminalwidget.h \ | 30 | terminalwidget.h \ |
31 | emulation_handler.h TECommon.h \ | 31 | emulation_handler.h TECommon.h \ |
32 | TEHistroy.h TEScreen.h TEWidget.h \ | 32 | TEHistroy.h TEScreen.h TEWidget.h \ |
33 | TEmuVt102.h TEmulation.h MyPty.h | 33 | TEmuVt102.h TEmulation.h MyPty.h \ |
34 | consoleconfigwidget.h | ||
34 | 35 | ||
35 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \ | 36 | SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \ |
36 | file_layer.cpp filetransfer.cpp \ | 37 | file_layer.cpp filetransfer.cpp \ |
@@ -59,7 +60,8 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp io_modem.cpp \ | |||
59 | terminalwidget.cpp \ | 60 | terminalwidget.cpp \ |
60 | emulation_handler.cpp TEHistory.cpp \ | 61 | emulation_handler.cpp TEHistory.cpp \ |
61 | TEScreen.cpp TEWidget.cpp \ | 62 | TEScreen.cpp TEWidget.cpp \ |
62 | TEmuVt102.cpp TEmulation.cpp MyPty.cpp | 63 | TEmuVt102.cpp TEmulation.cpp MyPty.cpp \ |
64 | consoleconfigwidget.cpp | ||
63 | 65 | ||
64 | 66 | ||
65 | INTERFACES = configurebase.ui editbase.ui | 67 | INTERFACES = configurebase.ui editbase.ui |