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
@@ -109,2 +109,3 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui )
109 connected = FALSE; 109 connected = FALSE;
110 m_script = 0;
110 111
@@ -134,2 +135,4 @@ EmulationLayer::~EmulationLayer()
134 delete screen[1]; 135 delete screen[1];
136 if (isRecording())
137 clearScript();
135 bulk_timer.stop(); 138 bulk_timer.stop();
@@ -230,2 +233,6 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev )
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 );
@@ -256,2 +263,31 @@ void EmulationLayer::onRcvBlock(const QByteArray &s )
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 --------------------------------------------------------------- --
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
@@ -34,2 +34,3 @@
34#include "keytrans.h" 34#include "keytrans.h"
35#include "script.h"
35 36
@@ -106,2 +107,18 @@ public:
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:
@@ -141,3 +158,3 @@ private:
141 int bulk_incnt; // bulk counter 158 int bulk_incnt; // bulk counter
142 159 Script *m_script;
143 160
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
@@ -7,3 +7,3 @@
7#include <qpe/resource.h> 7#include <qpe/resource.h>
8 8#include <opie/ofiledialog.h>
9 9
@@ -19,2 +19,3 @@
19#include "function_keyboard.h" 19#include "function_keyboard.h"
20#include "script.h"
20 21
@@ -40,2 +41,3 @@ void MainWindow::initUI() {
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 );
@@ -108,2 +110,17 @@ void MainWindow::initUI() {
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
@@ -128,2 +145,5 @@ void MainWindow::initUI() {
128 145
146 /* the scripts menu */
147 m_bar->insertItem( tr("Scripts"), m_scripts );
148
129 /* the settings menu */ 149 /* the settings menu */
@@ -191,2 +211,36 @@ void MainWindow::slotNew() {
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() {
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
@@ -61,3 +61,5 @@ private slots:
61 void slotOpenKeb(bool); 61 void slotOpenKeb(bool);
62 62 void slotRecordScript();
63 void slotSaveScript();
64 void slotRunScript();
63private: 65private:
@@ -90,2 +92,3 @@ private:
90 QPopupMenu* m_sessionsPop; 92 QPopupMenu* m_sessionsPop;
93 QPopupMenu* m_scripts;
91 QAction* m_connect; 94 QAction* m_connect;
@@ -96,2 +99,5 @@ private:
96 QAction* m_openKeys; 99 QAction* m_openKeys;
100 QAction* m_recordScript;
101 QAction* m_saveScript;
102 QAction* m_runScript;
97 103
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
@@ -32,3 +32,3 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.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
@@ -60,3 +60,3 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.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
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 */