summaryrefslogtreecommitdiff
Side-by-side diff
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 )
connected = FALSE;
+ m_script = 0;
@@ -134,2 +135,4 @@ EmulationLayer::~EmulationLayer()
delete screen[1];
+ if (isRecording())
+ clearScript();
bulk_timer.stop();
@@ -230,2 +233,6 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev )
// ibot: qbytearray is emited not char*
+
+ /* Are we currently recording a script? If so, store the typed character */
+ if (isRecording())
+ m_script->appendString(ev->text());
emit sndBlock( (QByteArray) c );
@@ -256,2 +263,31 @@ void EmulationLayer::onRcvBlock(const QByteArray &s )
+// Scripts ----------------------------------------------------------------- --
+
+
+Script *EmulationLayer::script() {
+ return m_script;
+}
+
+bool EmulationLayer::isRecording() {
+ return (m_script != 0);
+}
+
+void EmulationLayer::startRecording() {
+ if (!isRecording())
+ m_script = new Script();
+}
+
+void EmulationLayer::clearScript() {
+ if (isRecording()) {
+
+ }
+}
+
+void EmulationLayer::runScript(const Script *script) {
+ QByteArray a = QByteArray();
+ QString str = script->script();
+ a.setRawData(str.ascii(), str.length());
+ emit sndBlock(a);
+}
+
// 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 @@
#include "keytrans.h"
+#include "script.h"
@@ -106,2 +107,18 @@ public:
+ /* Scripts */
+
+ /* Create a new script and record all typed characters */
+ void startRecording();
+
+ /* Return whether we are currently recording a script */
+ bool isRecording();
+
+ /* Return the current script (or NULL) */
+ Script *script();
+
+ /* Stop recording and remove the current script from memory */
+ void clearScript();
+
+ /* Run a script by forwarding its keys to the EmulationLayer */
+ void runScript(const Script *);
protected:
@@ -141,3 +158,3 @@ private:
int bulk_incnt; // bulk counter
-
+ Script *m_script;
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 @@
#include <qpe/resource.h>
-
+#include <opie/ofiledialog.h>
@@ -19,2 +19,3 @@
#include "function_keyboard.h"
+#include "script.h"
@@ -40,2 +41,3 @@ void MainWindow::initUI() {
m_console = new QPopupMenu( this );
+ m_scripts = new QPopupMenu( this );
m_sessionsPop= new QPopupMenu( this );
@@ -108,2 +110,17 @@ void MainWindow::initUI() {
/*
+ * script actions
+ */
+ m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
+ m_recordScript->addTo(m_scripts);
+ connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
+
+ m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
+ m_saveScript->addTo(m_scripts);
+ connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
+
+ m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0);
+ m_runScript->addTo(m_scripts);
+ connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript()));
+
+ /*
* action that open/closes the keyboard
@@ -128,2 +145,5 @@ void MainWindow::initUI() {
+ /* the scripts menu */
+ m_bar->insertItem( tr("Scripts"), m_scripts );
+
/* the settings menu */
@@ -191,2 +211,36 @@ void MainWindow::slotNew() {
+void MainWindow::slotRecordScript() {
+ if (currentSession()) {
+ currentSession()->emulationLayer()->startRecording();
+ }
+}
+
+void MainWindow::slotSaveScript() {
+ if (currentSession() && currentSession()->emulationLayer()->isRecording()) {
+ MimeTypes types;
+ QStringList script;
+ script << "text/plain";
+ types.insert("Script", script);
+ QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types);
+ if (!filename.isEmpty()) {
+ currentSession()->emulationLayer()->script()->saveTo(filename);
+ currentSession()->emulationLayer()->clearScript();
+ }
+ }
+}
+
+void MainWindow::slotRunScript() {
+ if (currentSession()) {
+ MimeTypes types;
+ QStringList script;
+ script << "text/plain";
+ types.insert("Script", script);
+ QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types);
+ if (!filename.isEmpty()) {
+ Script script(DocLnk(filename).file());
+ currentSession()->emulationLayer()->runScript(&script);
+ }
+ }
+}
+
void 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:
void slotOpenKeb(bool);
-
+ void slotRecordScript();
+ void slotSaveScript();
+ void slotRunScript();
private:
@@ -90,2 +92,3 @@ private:
QPopupMenu* m_sessionsPop;
+ QPopupMenu* m_scripts;
QAction* m_connect;
@@ -96,2 +99,5 @@ private:
QAction* m_openKeys;
+ QAction* m_recordScript;
+ QAction* m_saveScript;
+ QAction* m_runScript;
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\
emulation_widget.h procctl.h \
- function_keyboard.h
+ function_keyboard.h script.h
@@ -60,3 +60,3 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
emulation_widget.cpp default.cpp procctl.cpp \
- function_keyboard.cpp
+ function_keyboard.cpp script.cpp
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 @@
+#include <qfile.h>
+#include <qtextstream.h>
+#include "script.h"
+
+Script::Script() {
+}
+
+Script::Script(const QString fileName) {
+ QFile file(fileName);
+ QTextStream stream(&file);
+ while (!stream.atEnd()) {
+ appendString(stream.readLine());
+ }
+}
+
+void Script::saveTo(const QString fileName) const {
+ QFile file(fileName);
+ file.open(IO_WriteOnly);
+ file.writeBlock(m_script.ascii(), m_script.length());
+ file.close();
+}
+
+
+void Script::appendString(const QString string) {
+ m_script += string;
+}
+
+QString Script::script() const {
+ return m_script;
+}
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 @@
+#ifndef CONSOLE_SCRIPT_H
+#define CONSOLE_SCRIPT_H
+
+#include <qstring.h>
+
+/* Very simple scripting - this class stores keys received
+ * by emulation_layer */
+
+class Script {
+public:
+ /* Construct an empty script */
+ Script();
+
+ /* Load a script from a text file */
+ Script(const QString fileName);
+
+ /* Append a line to the script */
+ void appendString(const QString string);
+
+ /* Save this script to a file */
+ void saveTo(const QString fileName) const;
+
+ /* Return the script's content */
+ QString script() const;
+protected:
+ QString m_script;
+};
+
+
+#endif /* CONSOLE_SCRIPT_H */