summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/emulation_layer.cpp36
-rw-r--r--noncore/apps/opie-console/emulation_layer.h19
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp56
-rw-r--r--noncore/apps/opie-console/mainwindow.h8
-rw-r--r--noncore/apps/opie-console/opie-console.pro4
-rw-r--r--noncore/apps/opie-console/script.cpp30
-rw-r--r--noncore/apps/opie-console/script.h30
7 files changed, 178 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/emulation_layer.cpp b/noncore/apps/opie-console/emulation_layer.cpp
index 5baf05c..265c11f 100644
--- a/noncore/apps/opie-console/emulation_layer.cpp
+++ b/noncore/apps/opie-console/emulation_layer.cpp
@@ -94,57 +94,60 @@
94 94
95/*! 95/*!
96*/ 96*/
97 97
98EmulationLayer::EmulationLayer( WidgetLayer* gui ) 98EmulationLayer::EmulationLayer( WidgetLayer* gui )
99: decoder((QTextDecoder*)NULL) 99: decoder((QTextDecoder*)NULL)
100{ 100{
101 this->gui = gui; 101 this->gui = gui;
102 102
103 screen[0] = new Screen(gui->lines(),gui->columns()); 103 screen[0] = new Screen(gui->lines(),gui->columns());
104 screen[1] = new Screen(gui->lines(),gui->columns()); 104 screen[1] = new Screen(gui->lines(),gui->columns());
105 scr = screen[0]; 105 scr = screen[0];
106 106
107 bulk_nlcnt = 0; // reset bulk newline counter 107 bulk_nlcnt = 0; // reset bulk newline counter
108 bulk_incnt = 0; // reset bulk counter 108 bulk_incnt = 0; // reset bulk counter
109 connected = FALSE; 109 connected = FALSE;
110 m_script = 0;
110 111
111 QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); 112 QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) );
112 QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), 113 QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ),
113 this,SLOT( onImageSizeChange( int, int ) ) ); 114 this,SLOT( onImageSizeChange( int, int ) ) );
114 QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), 115 QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ),
115 this,SLOT( historyCursorChange( int ) ) ); 116 this,SLOT( historyCursorChange( int ) ) );
116 QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), 117 QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ),
117 this,SLOT( onKeyPress( QKeyEvent* ) ) ); 118 this,SLOT( onKeyPress( QKeyEvent* ) ) );
118 QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), 119 QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ),
119 this,SLOT( onSelectionBegin( const int, const int ) ) ); 120 this,SLOT( onSelectionBegin( const int, const int ) ) );
120 QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), 121 QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ),
121 this,SLOT( onSelectionExtend( const int,const int ) ) ); 122 this,SLOT( onSelectionExtend( const int,const int ) ) );
122 QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), 123 QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ),
123 this,SLOT( setSelection( const bool ) ) ); 124 this,SLOT( setSelection( const bool ) ) );
124 QObject::connect(gui,SIGNAL( selectionCleared() ), 125 QObject::connect(gui,SIGNAL( selectionCleared() ),
125 this,SLOT( clearSelection() ) ); 126 this,SLOT( clearSelection() ) );
126} 127}
127 128
128/*! 129/*!
129*/ 130*/
130 131
131EmulationLayer::~EmulationLayer() 132EmulationLayer::~EmulationLayer()
132{ 133{
133 delete screen[0]; 134 delete screen[0];
134 delete screen[1]; 135 delete screen[1];
136 if (isRecording())
137 clearScript();
135 bulk_timer.stop(); 138 bulk_timer.stop();
136} 139}
137 140
138/*! change between primary and alternate screen 141/*! change between primary and alternate screen
139*/ 142*/
140 143
141void EmulationLayer::setScreen(int n) 144void EmulationLayer::setScreen(int n)
142{ 145{
143 scr = screen[n&1]; 146 scr = screen[n&1];
144} 147}
145 148
146void EmulationLayer::setHistory(bool on) 149void EmulationLayer::setHistory(bool on)
147{ 150{
148 screen[0]->setScroll(on); 151 screen[0]->setScroll(on);
149 if (!connected) return; 152 if (!connected) return;
150 showBulk(); 153 showBulk();
@@ -215,58 +218,91 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev )
215{ 218{
216 if (!connected) return; // someone else gets the keys 219 if (!connected) return; // someone else gets the keys
217 if (scr->getHistCursor() != scr->getHistLines()); 220 if (scr->getHistCursor() != scr->getHistLines());
218 scr->setHistCursor(scr->getHistLines()); 221 scr->setHistCursor(scr->getHistLines());
219 if (!ev->text().isEmpty()) 222 if (!ev->text().isEmpty())
220 { // A block of text 223 { // A block of text
221 // Note that the text is proper unicode. 224 // Note that the text is proper unicode.
222 // We should do a conversion here, but since this 225 // We should do a conversion here, but since this
223 // routine will never be used, we simply emit plain ascii. 226 // routine will never be used, we simply emit plain ascii.
224 sendString( ev->text().ascii() ); //,ev->text().length()); 227 sendString( ev->text().ascii() ); //,ev->text().length());
225 } 228 }
226 else if (ev->ascii()>0) 229 else if (ev->ascii()>0)
227 { 230 {
228 QByteArray c = QByteArray( 1 ); 231 QByteArray c = QByteArray( 1 );
229 c.at( 0 ) = ev->ascii(); 232 c.at( 0 ) = ev->ascii();
230 // ibot: qbytearray is emited not char* 233 // ibot: qbytearray is emited not char*
234
235 /* Are we currently recording a script? If so, store the typed character */
236 if (isRecording())
237 m_script->appendString(ev->text());
231 emit sndBlock( (QByteArray) c ); 238 emit sndBlock( (QByteArray) c );
232 } 239 }
233} 240}
234 241
235// Unblocking, Byte to Unicode translation --------------------------------- -- 242// Unblocking, Byte to Unicode translation --------------------------------- --
236 243
237/* 244/*
238 We are doing code conversion from locale to unicode first. 245 We are doing code conversion from locale to unicode first.
239*/ 246*/
240 247
241void EmulationLayer::onRcvBlock(const QByteArray &s ) 248void EmulationLayer::onRcvBlock(const QByteArray &s )
242{ 249{
243 bulkStart(); 250 bulkStart();
244 bulk_incnt += 1; 251 bulk_incnt += 1;
245 for (int i = 0; i < s.size(); i++) 252 for (int i = 0; i < s.size(); i++)
246 { 253 {
247 //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? 254 //TODO: ibot: maybe decoding qbytearray to unicode in io_layer?
248 QString result = decoder->toUnicode(&s[i],1); 255 QString result = decoder->toUnicode(&s[i],1);
249 int reslen = result.length(); 256 int reslen = result.length();
250 for (int j = 0; j < reslen; j++) 257 for (int j = 0; j < reslen; j++)
251 onRcvChar(result[j].unicode()); 258 onRcvChar(result[j].unicode());
252 if (s[i] == '\n') bulkNewline(); 259 if (s[i] == '\n') bulkNewline();
253 } 260 }
254 bulkEnd(); 261 bulkEnd();
255} 262}
256 263
264// Scripts ----------------------------------------------------------------- --
265
266
267Script *EmulationLayer::script() {
268 return m_script;
269}
270
271bool EmulationLayer::isRecording() {
272 return (m_script != 0);
273}
274
275void EmulationLayer::startRecording() {
276 if (!isRecording())
277 m_script = new Script();
278}
279
280void EmulationLayer::clearScript() {
281 if (isRecording()) {
282
283 }
284}
285
286void EmulationLayer::runScript(const Script *script) {
287 QByteArray a = QByteArray();
288 QString str = script->script();
289 a.setRawData(str.ascii(), str.length());
290 emit sndBlock(a);
291}
292
257// Selection --------------------------------------------------------------- -- 293// Selection --------------------------------------------------------------- --
258 294
259void EmulationLayer::onSelectionBegin(const int x, const int y) { 295void EmulationLayer::onSelectionBegin(const int x, const int y) {
260 if (!connected) return; 296 if (!connected) return;
261 scr->setSelBeginXY(x,y); 297 scr->setSelBeginXY(x,y);
262 showBulk(); 298 showBulk();
263} 299}
264 300
265void EmulationLayer::onSelectionExtend(const int x, const int y) { 301void EmulationLayer::onSelectionExtend(const int x, const int y) {
266 if (!connected) return; 302 if (!connected) return;
267 scr->setSelExtentXY(x,y); 303 scr->setSelExtentXY(x,y);
268 showBulk(); 304 showBulk();
269} 305}
270 306
271void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { 307void EmulationLayer::setSelection(const BOOL preserve_line_breaks) {
272 if (!connected) return; 308 if (!connected) return;
diff --git a/noncore/apps/opie-console/emulation_layer.h b/noncore/apps/opie-console/emulation_layer.h
index 91a4856..928ad04 100644
--- a/noncore/apps/opie-console/emulation_layer.h
+++ b/noncore/apps/opie-console/emulation_layer.h
@@ -19,32 +19,33 @@
19 /* */ 19 /* */
20/* made to a layer between io_layer and widget */ 20/* made to a layer between io_layer and widget */
21 /* */ 21 /* */
22/* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ 22/* Copyright (C) 2002 by opie developers <opie@handhelds.org> */
23 /* */ 23 /* */
24/* -------------------------------------------------------------------------- */ 24/* -------------------------------------------------------------------------- */
25 25
26#ifndef EMULATION_LAYER_H 26#ifndef EMULATION_LAYER_H
27#define EMULATION_LAYER_H 27#define EMULATION_LAYER_H
28 28
29#include "widget_layer.h" 29#include "widget_layer.h"
30#include "screen.h" 30#include "screen.h"
31#include <qtimer.h> 31#include <qtimer.h>
32#include <stdio.h> 32#include <stdio.h>
33#include <qtextcodec.h> 33#include <qtextcodec.h>
34#include "keytrans.h" 34#include "keytrans.h"
35#include "script.h"
35 36
36class EmulationLayer : public QObject 37class EmulationLayer : public QObject
37{ Q_OBJECT 38{ Q_OBJECT
38 39
39public: 40public:
40 41
41 EmulationLayer( WidgetLayer* gui ); 42 EmulationLayer( WidgetLayer* gui );
42 ~EmulationLayer(); 43 ~EmulationLayer();
43 44
44public: 45public:
45 virtual void setHistory(bool on); 46 virtual void setHistory(bool on);
46 virtual bool history(); 47 virtual bool history();
47 48
48public slots: // signals incoming from Widget 49public slots: // signals incoming from Widget
49 50
50 virtual void onImageSizeChange(int lines, int columns); 51 virtual void onImageSizeChange(int lines, int columns);
@@ -91,32 +92,48 @@ public:
91 * @deprecated use qbytearray instead 92 * @deprecated use qbytearray instead
92 */ 93 */
93 virtual void sendString(const char*) = 0; 94 virtual void sendString(const char*) = 0;
94 95
95 /** 96 /**
96 * sends a string to IOLayer 97 * sends a string to IOLayer
97 * encodes to suit emulation before 98 * encodes to suit emulation before
98 */ 99 */
99 virtual void sendString(const QByteArray&) = 0; 100 virtual void sendString(const QByteArray&) = 0;
100 101
101 virtual void setConnect(bool r); 102 virtual void setConnect(bool r);
102 void setColumns(int columns); 103 void setColumns(int columns);
103 104
104 void setKeytrans(int no); 105 void setKeytrans(int no);
105 void setKeytrans(const char * no); 106 void setKeytrans(const char * no);
106 107
108 /* Scripts */
109
110 /* Create a new script and record all typed characters */
111 void startRecording();
112
113 /* Return whether we are currently recording a script */
114 bool isRecording();
115
116 /* Return the current script (or NULL) */
117 Script *script();
118
119 /* Stop recording and remove the current script from memory */
120 void clearScript();
121
122 /* Run a script by forwarding its keys to the EmulationLayer */
123 void runScript(const Script *);
107protected: 124protected:
108 125
109 WidgetLayer* gui; 126 WidgetLayer* gui;
110 Screen* scr; // referes to one `screen' 127 Screen* scr; // referes to one `screen'
111 Screen* screen[2]; // 0 = primary, 1 = alternate 128 Screen* screen[2]; // 0 = primary, 1 = alternate
112 void setScreen(int n); // set `scr' to `screen[n]' 129 void setScreen(int n); // set `scr' to `screen[n]'
113 130
114 bool connected; // communicate with widget 131 bool connected; // communicate with widget
115 132
116 void setCodec(int c); // codec number, 0 = locale, 1=utf8 133 void setCodec(int c); // codec number, 0 = locale, 1=utf8
117 134
118 QTextCodec* codec; 135 QTextCodec* codec;
119 QTextCodec* localeCodec; 136 QTextCodec* localeCodec;
120 QTextDecoder* decoder; 137 QTextDecoder* decoder;
121 138
122 KeyTrans* keytrans; 139 KeyTrans* keytrans;
@@ -126,21 +143,21 @@ protected:
126private slots: // triggered by timer 143private slots: // triggered by timer
127 144
128 void showBulk(); 145 void showBulk();
129 146
130private: 147private:
131 148
132 void bulkNewline(); 149 void bulkNewline();
133 void bulkStart(); 150 void bulkStart();
134 void bulkEnd(); 151 void bulkEnd();
135 152
136private: 153private:
137 154
138 QTimer bulk_timer; 155 QTimer bulk_timer;
139 int bulk_nlcnt; // bulk newline counter 156 int bulk_nlcnt; // bulk newline counter
140 char* SelectedText; 157 char* SelectedText;
141 int bulk_incnt; // bulk counter 158 int bulk_incnt; // bulk counter
142 159 Script *m_script;
143 160
144}; 161};
145 162
146#endif // ifndef EMULATION_H 163#endif // ifndef EMULATION_H
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 8f5d56b..46c5bed 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,56 +1,58 @@
1 1
2#include <qaction.h> 2#include <qaction.h>
3#include <qmenubar.h> 3#include <qmenubar.h>
4#include <qlabel.h> 4#include <qlabel.h>
5#include <qpopupmenu.h> 5#include <qpopupmenu.h>
6#include <qtoolbar.h> 6#include <qtoolbar.h>
7#include <qpe/resource.h> 7#include <qpe/resource.h>
8 8#include <opie/ofiledialog.h>
9 9
10#include "profileeditordialog.h" 10#include "profileeditordialog.h"
11#include "configdialog.h" 11#include "configdialog.h"
12#include "default.h" 12#include "default.h"
13#include "metafactory.h" 13#include "metafactory.h"
14#include "profile.h" 14#include "profile.h"
15#include "profilemanager.h" 15#include "profilemanager.h"
16#include "mainwindow.h" 16#include "mainwindow.h"
17#include "tabwidget.h" 17#include "tabwidget.h"
18#include "transferdialog.h" 18#include "transferdialog.h"
19#include "function_keyboard.h" 19#include "function_keyboard.h"
20#include "script.h"
20 21
21MainWindow::MainWindow() { 22MainWindow::MainWindow() {
22 m_factory = new MetaFactory(); 23 m_factory = new MetaFactory();
23 Default def(m_factory); 24 Default def(m_factory);
24 m_sessions.setAutoDelete( TRUE ); 25 m_sessions.setAutoDelete( TRUE );
25 m_curSession = 0; 26 m_curSession = 0;
26 m_manager = new ProfileManager( m_factory ); 27 m_manager = new ProfileManager( m_factory );
27 m_manager->load(); 28 m_manager->load();
28 29
29 initUI(); 30 initUI();
30 populateProfiles(); 31 populateProfiles();
31} 32}
32void MainWindow::initUI() { 33void MainWindow::initUI() {
33 setToolBarsMovable( FALSE ); 34 setToolBarsMovable( FALSE );
34 35
35 /* tool bar for the menu */ 36 /* tool bar for the menu */
36 m_tool = new QToolBar( this ); 37 m_tool = new QToolBar( this );
37 m_tool->setHorizontalStretchable( TRUE ); 38 m_tool->setHorizontalStretchable( TRUE );
38 39
39 m_bar = new QMenuBar( m_tool ); 40 m_bar = new QMenuBar( m_tool );
40 m_console = new QPopupMenu( this ); 41 m_console = new QPopupMenu( this );
42 m_scripts = new QPopupMenu( this );
41 m_sessionsPop= new QPopupMenu( this ); 43 m_sessionsPop= new QPopupMenu( this );
42 m_settings = new QPopupMenu( this ); 44 m_settings = new QPopupMenu( this );
43 45
44 /* add a toolbar for icons */ 46 /* add a toolbar for icons */
45 m_icons = new QToolBar(this); 47 m_icons = new QToolBar(this);
46 48
47 /* 49 /*
48 * new Action for new sessions 50 * new Action for new sessions
49 */ 51 */
50 QAction* a = new QAction(tr("New Connection"), 52 QAction* a = new QAction(tr("New Connection"),
51 Resource::loadPixmap( "new" ), 53 Resource::loadPixmap( "new" ),
52 QString::null, 0, this, 0); 54 QString::null, 0, this, 0);
53 a->addTo( m_console ); 55 a->addTo( m_console );
54 a->addTo( m_icons ); 56 a->addTo( m_icons );
55 connect(a, SIGNAL(activated() ), 57 connect(a, SIGNAL(activated() ),
56 this, SLOT(slotNew() ) ); 58 this, SLOT(slotNew() ) );
@@ -93,52 +95,70 @@ void MainWindow::initUI() {
93 a->addTo( m_console ); 95 a->addTo( m_console );
94 connect(a, SIGNAL(activated() ), 96 connect(a, SIGNAL(activated() ),
95 this, SLOT(slotClose() ) ); 97 this, SLOT(slotClose() ) );
96 98
97 /* 99 /*
98 * the settings action 100 * the settings action
99 */ 101 */
100 m_setProfiles = new QAction(tr("Configure Profiles"), 102 m_setProfiles = new QAction(tr("Configure Profiles"),
101 Resource::loadPixmap( "SettingsIcon" ), 103 Resource::loadPixmap( "SettingsIcon" ),
102 QString::null, 0, this, 0); 104 QString::null, 0, this, 0);
103 m_setProfiles->addTo( m_settings ); 105 m_setProfiles->addTo( m_settings );
104 m_setProfiles->addTo( m_icons ); 106 m_setProfiles->addTo( m_icons );
105 connect( m_setProfiles, SIGNAL(activated() ), 107 connect( m_setProfiles, SIGNAL(activated() ),
106 this, SLOT(slotConfigure() ) ); 108 this, SLOT(slotConfigure() ) );
107 109
108 /* 110 /*
111 * script actions
112 */
113 m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
114 m_recordScript->addTo(m_scripts);
115 connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
116
117 m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
118 m_saveScript->addTo(m_scripts);
119 connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
120
121 m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0);
122 m_runScript->addTo(m_scripts);
123 connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript()));
124
125 /*
109 * action that open/closes the keyboard 126 * action that open/closes the keyboard
110 */ 127 */
111 m_openKeys = new QAction (tr("Open Keyboard..."), 128 m_openKeys = new QAction (tr("Open Keyboard..."),
112 Resource::loadPixmap( "down" ), 129 Resource::loadPixmap( "down" ),
113 QString::null, 0, this, 0); 130 QString::null, 0, this, 0);
114 131
115 m_openKeys->setToggleAction(true); 132 m_openKeys->setToggleAction(true);
116 133
117 connect (m_openKeys, SIGNAL(toggled(bool)), 134 connect (m_openKeys, SIGNAL(toggled(bool)),
118 this, SLOT(slotOpenKeb(bool))); 135 this, SLOT(slotOpenKeb(bool)));
119 m_openKeys->addTo(m_icons); 136 m_openKeys->addTo(m_icons);
120 137
121 138
122 /* insert the submenu */ 139 /* insert the submenu */
123 m_console->insertItem(tr("New from Profile"), m_sessionsPop, 140 m_console->insertItem(tr("New from Profile"), m_sessionsPop,
124 -1, 0); 141 -1, 0);
125 142
126 /* insert the connection menu */ 143 /* insert the connection menu */
127 m_bar->insertItem( tr("Connection"), m_console ); 144 m_bar->insertItem( tr("Connection"), m_console );
128 145
146 /* the scripts menu */
147 m_bar->insertItem( tr("Scripts"), m_scripts );
148
129 /* the settings menu */ 149 /* the settings menu */
130 m_bar->insertItem( tr("Settings"), m_settings ); 150 m_bar->insertItem( tr("Settings"), m_settings );
131 151
132 /* and the keyboard */ 152 /* and the keyboard */
133 m_keyBar = new QToolBar(this); 153 m_keyBar = new QToolBar(this);
134 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE ); 154 addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
135 m_keyBar->setHorizontalStretchable( TRUE ); 155 m_keyBar->setHorizontalStretchable( TRUE );
136 m_keyBar->hide(); 156 m_keyBar->hide();
137 157
138 m_kb = new FunctionKeyboard(m_keyBar); 158 m_kb = new FunctionKeyboard(m_keyBar);
139 159
140 /* 160 /*
141 * connect to the menu activation 161 * connect to the menu activation
142 */ 162 */
143 connect( m_sessionsPop, SIGNAL(activated( int ) ), 163 connect( m_sessionsPop, SIGNAL(activated( int ) ),
144 this, SLOT(slotProfile( int ) ) ); 164 this, SLOT(slotProfile( int ) ) );
@@ -176,32 +196,66 @@ Session* MainWindow::currentSession() {
176} 196}
177 197
178QList<Session> MainWindow::sessions() { 198QList<Session> MainWindow::sessions() {
179 return m_sessions; 199 return m_sessions;
180} 200}
181 201
182void MainWindow::slotNew() { 202void MainWindow::slotNew() {
183 qWarning("New Connection"); 203 qWarning("New Connection");
184 ProfileEditorDialog dlg(factory() ); 204 ProfileEditorDialog dlg(factory() );
185 int ret = dlg.exec(); 205 int ret = dlg.exec();
186 206
187 if ( ret == QDialog::Accepted ) { 207 if ( ret == QDialog::Accepted ) {
188 create( dlg.profile() ); 208 create( dlg.profile() );
189 } 209 }
190} 210}
191 211
212void MainWindow::slotRecordScript() {
213 if (currentSession()) {
214 currentSession()->emulationLayer()->startRecording();
215 }
216}
217
218void MainWindow::slotSaveScript() {
219 if (currentSession() && currentSession()->emulationLayer()->isRecording()) {
220 MimeTypes types;
221 QStringList script;
222 script << "text/plain";
223 types.insert("Script", script);
224 QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types);
225 if (!filename.isEmpty()) {
226 currentSession()->emulationLayer()->script()->saveTo(filename);
227 currentSession()->emulationLayer()->clearScript();
228 }
229 }
230}
231
232void MainWindow::slotRunScript() {
233 if (currentSession()) {
234 MimeTypes types;
235 QStringList script;
236 script << "text/plain";
237 types.insert("Script", script);
238 QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types);
239 if (!filename.isEmpty()) {
240 Script script(DocLnk(filename).file());
241 currentSession()->emulationLayer()->runScript(&script);
242 }
243 }
244}
245
192void MainWindow::slotConnect() { 246void MainWindow::slotConnect() {
193 if ( currentSession() ) 247 if ( currentSession() )
194 currentSession()->layer()->open(); 248 currentSession()->layer()->open();
195} 249}
196 250
197void MainWindow::slotDisconnect() { 251void MainWindow::slotDisconnect() {
198 if ( currentSession() ) 252 if ( currentSession() )
199 currentSession()->layer()->close(); 253 currentSession()->layer()->close();
200} 254}
201 255
202void MainWindow::slotTerminate() { 256void MainWindow::slotTerminate() {
203 if ( currentSession() ) 257 if ( currentSession() )
204 currentSession()->layer()->close(); 258 currentSession()->layer()->close();
205 259
206 slotClose(); 260 slotClose();
207 /* FIXME move to the next session */ 261 /* FIXME move to the next session */
diff --git a/noncore/apps/opie-console/mainwindow.h b/noncore/apps/opie-console/mainwindow.h
index 73bb285..94144a4 100644
--- a/noncore/apps/opie-console/mainwindow.h
+++ b/noncore/apps/opie-console/mainwindow.h
@@ -46,57 +46,63 @@ public:
46 /** 46 /**
47 * 47 *
48 */ 48 */
49 ProfileManager* manager(); 49 ProfileManager* manager();
50 TabWidget* tabWidget(); 50 TabWidget* tabWidget();
51 51
52private slots: 52private slots:
53 void slotNew(); 53 void slotNew();
54 void slotConnect(); 54 void slotConnect();
55 void slotDisconnect(); 55 void slotDisconnect();
56 void slotTerminate(); 56 void slotTerminate();
57 void slotConfigure(); 57 void slotConfigure();
58 void slotClose(); 58 void slotClose();
59 void slotProfile(int); 59 void slotProfile(int);
60 void slotTransfer(); 60 void slotTransfer();
61 void slotOpenKeb(bool); 61 void slotOpenKeb(bool);
62 62 void slotRecordScript();
63 void slotSaveScript();
64 void slotRunScript();
63private: 65private:
64 void initUI(); 66 void initUI();
65 void populateProfiles(); 67 void populateProfiles();
66 void create( const Profile& ); 68 void create( const Profile& );
67 /** 69 /**
68 * the current session 70 * the current session
69 */ 71 */
70 Session* m_curSession; 72 Session* m_curSession;
71 73
72 /** 74 /**
73 * the session list 75 * the session list
74 */ 76 */
75 QList<Session> m_sessions; 77 QList<Session> m_sessions;
76 78
77 /** 79 /**
78 * the metafactory 80 * the metafactory
79 */ 81 */
80 MetaFactory* m_factory; 82 MetaFactory* m_factory;
81 ProfileManager* m_manager; 83 ProfileManager* m_manager;
82 84
83 TabWidget* m_consoleWindow; 85 TabWidget* m_consoleWindow;
84 QToolBar* m_tool; 86 QToolBar* m_tool;
85 QToolBar* m_icons; 87 QToolBar* m_icons;
86 QToolBar* m_keyBar; 88 QToolBar* m_keyBar;
87 QMenuBar* m_bar; 89 QMenuBar* m_bar;
88 QPopupMenu* m_console; 90 QPopupMenu* m_console;
89 QPopupMenu* m_settings; 91 QPopupMenu* m_settings;
90 QPopupMenu* m_sessionsPop; 92 QPopupMenu* m_sessionsPop;
93 QPopupMenu* m_scripts;
91 QAction* m_connect; 94 QAction* m_connect;
92 QAction* m_disconnect; 95 QAction* m_disconnect;
93 QAction* m_terminate; 96 QAction* m_terminate;
94 QAction* m_transfer; 97 QAction* m_transfer;
95 QAction* m_setProfiles; 98 QAction* m_setProfiles;
96 QAction* m_openKeys; 99 QAction* m_openKeys;
100 QAction* m_recordScript;
101 QAction* m_saveScript;
102 QAction* m_runScript;
97 103
98 FunctionKeyboard *m_kb; 104 FunctionKeyboard *m_kb;
99}; 105};
100 106
101 107
102#endif 108#endif
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index b07f10a..8e39a48 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -17,52 +17,52 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h\
17 vt102emulation.h \ 17 vt102emulation.h \
18 common.h \ 18 common.h \
19 history.h \ 19 history.h \
20 screen.h \ 20 screen.h \
21 keytrans.h \ 21 keytrans.h \
22 widget_layer.h \ 22 widget_layer.h \
23 transferdialog.h \ 23 transferdialog.h \
24 profiledialogwidget.h \ 24 profiledialogwidget.h \
25 profileeditordialog.h \ 25 profileeditordialog.h \
26 default.h \ 26 default.h \
27 terminalwidget.h \ 27 terminalwidget.h \
28 iolayerbase.h \ 28 iolayerbase.h \
29 serialconfigwidget.h irdaconfigwidget.h \ 29 serialconfigwidget.h irdaconfigwidget.h \
30 btconfigwidget.h modemconfigwidget.h \ 30 btconfigwidget.h modemconfigwidget.h \
31 atconfigdialog.h dialdialog.h \ 31 atconfigdialog.h dialdialog.h \
32 emulation_widget.h procctl.h \ 32 emulation_widget.h procctl.h \
33 function_keyboard.h 33 function_keyboard.h script.h
34 34
35SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \ 35SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
36 file_layer.cpp filetransfer.cpp \ 36 file_layer.cpp filetransfer.cpp \
37 main.cpp \ 37 main.cpp \
38 metafactory.cpp \ 38 metafactory.cpp \
39 session.cpp \ 39 session.cpp \
40 mainwindow.cpp \ 40 mainwindow.cpp \
41 profile.cpp \ 41 profile.cpp \
42 profileconfig.cpp \ 42 profileconfig.cpp \
43 profilemanager.cpp \ 43 profilemanager.cpp \
44 tabwidget.cpp \ 44 tabwidget.cpp \
45 configdialog.cpp \ 45 configdialog.cpp \
46 emulation_layer.cpp \ 46 emulation_layer.cpp \
47 vt102emulation.cpp \ 47 vt102emulation.cpp \
48 history.cpp \ 48 history.cpp \
49 screen.cpp \ 49 screen.cpp \
50 keytrans.cpp \ 50 keytrans.cpp \
51 widget_layer.cpp \ 51 widget_layer.cpp \
52 transferdialog.cpp \ 52 transferdialog.cpp \
53 profiledialogwidget.cpp \ 53 profiledialogwidget.cpp \
54 profileeditordialog.cpp \ 54 profileeditordialog.cpp \
55 terminalwidget.cpp \ 55 terminalwidget.cpp \
56 iolayerbase.cpp \ 56 iolayerbase.cpp \
57 serialconfigwidget.cpp irdaconfigwidget.cpp \ 57 serialconfigwidget.cpp irdaconfigwidget.cpp \
58 btconfigwidget.cpp modemconfigwidget.cpp \ 58 btconfigwidget.cpp modemconfigwidget.cpp \
59 atconfigdialog.cpp dialdialog.cpp \ 59 atconfigdialog.cpp dialdialog.cpp \
60 emulation_widget.cpp default.cpp procctl.cpp \ 60 emulation_widget.cpp default.cpp procctl.cpp \
61 function_keyboard.cpp 61 function_keyboard.cpp script.cpp
62 62
63INTERFACES = configurebase.ui editbase.ui 63INTERFACES = configurebase.ui editbase.ui
64INCLUDEPATH += $(OPIEDIR)/include 64INCLUDEPATH += $(OPIEDIR)/include
65DEPENDPATH += $(OPIEDIR)/include 65DEPENDPATH += $(OPIEDIR)/include
66LIBS += -lqpe -lopie 66LIBS += -lqpe -lopie
67TARGET = opie-console 67TARGET = opie-console
68 68
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp
new file mode 100644
index 0000000..a09fab6
--- a/dev/null
+++ b/noncore/apps/opie-console/script.cpp
@@ -0,0 +1,30 @@
1#include <qfile.h>
2#include <qtextstream.h>
3#include "script.h"
4
5Script::Script() {
6}
7
8Script::Script(const QString fileName) {
9 QFile file(fileName);
10 QTextStream stream(&file);
11 while (!stream.atEnd()) {
12 appendString(stream.readLine());
13 }
14}
15
16void Script::saveTo(const QString fileName) const {
17 QFile file(fileName);
18 file.open(IO_WriteOnly);
19 file.writeBlock(m_script.ascii(), m_script.length());
20 file.close();
21}
22
23
24void Script::appendString(const QString string) {
25 m_script += string;
26}
27
28QString Script::script() const {
29 return m_script;
30}
diff --git a/noncore/apps/opie-console/script.h b/noncore/apps/opie-console/script.h
new file mode 100644
index 0000000..dc2351b
--- a/dev/null
+++ b/noncore/apps/opie-console/script.h
@@ -0,0 +1,30 @@
1#ifndef CONSOLE_SCRIPT_H
2#define CONSOLE_SCRIPT_H
3
4#include <qstring.h>
5
6/* Very simple scripting - this class stores keys received
7 * by emulation_layer */
8
9class Script {
10public:
11 /* Construct an empty script */
12 Script();
13
14 /* Load a script from a text file */
15 Script(const QString fileName);
16
17 /* Append a line to the script */
18 void appendString(const QString string);
19
20 /* Save this script to a file */
21 void saveTo(const QString fileName) const;
22
23 /* Return the script's content */
24 QString script() const;
25protected:
26 QString m_script;
27};
28
29
30#endif /* CONSOLE_SCRIPT_H */