author | wazlaf <wazlaf> | 2002-10-20 14:53:08 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-10-20 14:53:08 (UTC) |
commit | 18ba3be9ca69c42476e310649e3068d2d5f8a03b (patch) (side-by-side diff) | |
tree | d6a68e8f1a319ef8320d714356beebcf440a630f | |
parent | 9f442f5af601d1e15bb4d0509ed012e61609260d (diff) | |
download | opie-18ba3be9ca69c42476e310649e3068d2d5f8a03b.zip opie-18ba3be9ca69c42476e310649e3068d2d5f8a03b.tar.gz opie-18ba3be9ca69c42476e310649e3068d2d5f8a03b.tar.bz2 |
scripting fixed (moved from emulation_layer to emulation_handler). Scripts now use QByteArray instead of QString
-rw-r--r-- | noncore/apps/opie-console/emulation_handler.cpp | 34 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_handler.h | 19 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_layer.cpp | 36 | ||||
-rw-r--r-- | noncore/apps/opie-console/emulation_layer.h | 18 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 16 | ||||
-rw-r--r-- | noncore/apps/opie-console/script.cpp | 15 | ||||
-rw-r--r-- | noncore/apps/opie-console/script.h | 6 |
7 files changed, 68 insertions, 76 deletions
diff --git a/noncore/apps/opie-console/emulation_handler.cpp b/noncore/apps/opie-console/emulation_handler.cpp index 8846959..df8e573 100644 --- a/noncore/apps/opie-console/emulation_handler.cpp +++ b/noncore/apps/opie-console/emulation_handler.cpp @@ -8,3 +8,3 @@ #include "emulation_handler.h" - +#include "script.h" @@ -15,2 +15,3 @@ EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const c m_teWid->setMinimumSize(150, 70 ); + m_script = 0; parent->resize( m_teWid->calcSize(80, 24 ) ); @@ -30,2 +31,4 @@ EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const c EmulationHandler::~EmulationHandler() { + if (isRecording()) + clearScript(); delete m_teEmu; @@ -33,2 +36,3 @@ EmulationHandler::~EmulationHandler() { } + void EmulationHandler::load( const Profile& prof) { @@ -47,2 +51,4 @@ void EmulationHandler::recvEmulation(const char* src, int len ) { + if (isRecording()) + m_script->append(ar); emit send(ar); @@ -147 +153,27 @@ QPushButton* EmulationHandler::cornerButton() { } + + +Script *EmulationHandler::script() { + return m_script; +} + +bool EmulationHandler::isRecording() { + return (m_script != 0); +} + +void EmulationHandler::startRecording() { + if (!isRecording()) + m_script = new Script(); +} + +void EmulationHandler::clearScript() { + if (isRecording()) { + delete m_script; + m_script = 0; + } +} + +void EmulationHandler::runScript(const Script *script) { + emit send(script->script()); +} + diff --git a/noncore/apps/opie-console/emulation_handler.h b/noncore/apps/opie-console/emulation_handler.h index 9ceafc6..7ca2cf3 100644 --- a/noncore/apps/opie-console/emulation_handler.h +++ b/noncore/apps/opie-console/emulation_handler.h @@ -31,2 +31,3 @@ class TEmulation; class QFont; +class Script; class EmulationHandler : public QObject { @@ -50,2 +51,18 @@ public: QPushButton* cornerButton(); + + /* 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 *); @@ -69,3 +86,3 @@ private: TEmulation* m_teEmu; - + Script * m_script; }; diff --git a/noncore/apps/opie-console/emulation_layer.cpp b/noncore/apps/opie-console/emulation_layer.cpp index 265c11f..6a2679e 100644 --- a/noncore/apps/opie-console/emulation_layer.cpp +++ b/noncore/apps/opie-console/emulation_layer.cpp @@ -109,3 +109,2 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui ) connected = FALSE; - m_script = 0; @@ -135,4 +134,2 @@ EmulationLayer::~EmulationLayer() delete screen[1]; - if (isRecording()) - clearScript(); bulk_timer.stop(); @@ -234,5 +231,2 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev ) - /* Are we currently recording a script? If so, store the typed character */ - if (isRecording()) - m_script->appendString(ev->text()); emit sndBlock( (QByteArray) c ); @@ -263,31 +257,2 @@ 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 --------------------------------------------------------------- -- @@ -408 +373,2 @@ void EmulationLayer::setColumns(int columns) } + diff --git a/noncore/apps/opie-console/emulation_layer.h b/noncore/apps/opie-console/emulation_layer.h index 928ad04..73e5bf6 100644 --- a/noncore/apps/opie-console/emulation_layer.h +++ b/noncore/apps/opie-console/emulation_layer.h @@ -34,3 +34,2 @@ #include "keytrans.h" -#include "script.h" @@ -107,18 +106,2 @@ 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: @@ -158,3 +141,2 @@ 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 a7541f0..49f9653 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp @@ -288,6 +288,5 @@ void MainWindow::slotNew() { void MainWindow::slotRecordScript() { -/* if (currentSession()) { - currentSession()->emulationLayer()->startRecording(); + if (currentSession()) { + currentSession()->emulationHandler()->startRecording(); } - */ } @@ -295,3 +294,3 @@ void MainWindow::slotRecordScript() { void MainWindow::slotSaveScript() { -/* if (currentSession() && currentSession()->emulationLayer()->isRecording()) { + if (currentSession() && currentSession()->emulationHandler()->isRecording()) { MimeTypes types; @@ -302,7 +301,6 @@ void MainWindow::slotSaveScript() { if (!filename.isEmpty()) { - currentSession()->emulationLayer()->script()->saveTo(filename); - currentSession()->emulationLayer()->clearScript(); + currentSession()->emulationHandler()->script()->saveTo(filename); + currentSession()->emulationHandler()->clearScript(); } } - */ } @@ -310,3 +308,2 @@ void MainWindow::slotSaveScript() { void MainWindow::slotRunScript() { -/* if (currentSession()) { @@ -319,6 +316,5 @@ void MainWindow::slotRunScript() { Script script(DocLnk(filename).file()); - currentSession()->emulationLayer()->runScript(&script); + currentSession()->emulationHandler()->runScript(&script); } } - */ } diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp index a09fab6..9cb1cd3 100644 --- a/noncore/apps/opie-console/script.cpp +++ b/noncore/apps/opie-console/script.cpp @@ -9,6 +9,3 @@ Script::Script(const QString fileName) { QFile file(fileName); - QTextStream stream(&file); - while (!stream.atEnd()) { - appendString(stream.readLine()); - } + m_script = file.readAll(); } @@ -18,3 +15,3 @@ void Script::saveTo(const QString fileName) const { file.open(IO_WriteOnly); - file.writeBlock(m_script.ascii(), m_script.length()); + file.writeBlock(m_script); file.close(); @@ -23,7 +20,9 @@ void Script::saveTo(const QString fileName) const { -void Script::appendString(const QString string) { - m_script += string; +void Script::append(const QByteArray &data) { + int size = m_script.size(); + m_script.resize(size + data.size()); + memcpy(m_script.data() + size, data.data(), data.size()); } -QString Script::script() const { +QByteArray Script::script() const { return m_script; diff --git a/noncore/apps/opie-console/script.h b/noncore/apps/opie-console/script.h index dc2351b..b3eac7f 100644 --- a/noncore/apps/opie-console/script.h +++ b/noncore/apps/opie-console/script.h @@ -17,3 +17,3 @@ public: /* Append a line to the script */ - void appendString(const QString string); + void append(const QByteArray &data); @@ -23,5 +23,5 @@ public: /* Return the script's content */ - QString script() const; + QByteArray script() const; protected: - QString m_script; + QByteArray m_script; }; |