From 18ba3be9ca69c42476e310649e3068d2d5f8a03b Mon Sep 17 00:00:00 2001 From: wazlaf Date: Sun, 20 Oct 2002 14:53:08 +0000 Subject: scripting fixed (moved from emulation_layer to emulation_handler). Scripts now use QByteArray instead of QString --- 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 @@ -6,13 +6,14 @@ #include "profile.h" #include "emulation_handler.h" - +#include "script.h" EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) : QObject(0, name ) { m_teWid = new TEWidget( parent, "TerminalMain"); m_teWid->setMinimumSize(150, 70 ); + m_script = 0; parent->resize( m_teWid->calcSize(80, 24 ) ); m_teEmu = new TEmuVt102(m_teWid ); @@ -28,9 +29,12 @@ EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const c } EmulationHandler::~EmulationHandler() { + if (isRecording()) + clearScript(); delete m_teEmu; delete m_teWid; } + void EmulationHandler::load( const Profile& prof) { m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); int num = prof.readNumEntry("Color"); @@ -45,6 +49,8 @@ void EmulationHandler::recvEmulation(const char* src, int len ) { memcpy(ar.data(), src, sizeof(char) * len ); + if (isRecording()) + m_script->append(ar); emit send(ar); } QWidget* EmulationHandler::widget() { @@ -145,3 +151,29 @@ QColor EmulationHandler::backColor(int col ) { QPushButton* EmulationHandler::cornerButton() { return m_teWid->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 @@ -29,6 +29,7 @@ class QPushButton; class TEWidget; class TEmulation; class QFont; +class Script; class EmulationHandler : public QObject { Q_OBJECT public: @@ -48,6 +49,22 @@ public: QWidget* widget(); void setColor( const QColor& fore, const QColor& back ); 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 *); signals: void send( const QByteArray& ); @@ -67,7 +84,7 @@ private: private: TEWidget* m_teWid; TEmulation* m_teEmu; - + Script * m_script; }; #endif 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 @@ -107,7 +107,6 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui ) bulk_nlcnt = 0; // reset bulk newline counter bulk_incnt = 0; // reset bulk counter connected = FALSE; - m_script = 0; QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), @@ -133,8 +132,6 @@ EmulationLayer::~EmulationLayer() { delete screen[0]; delete screen[1]; - if (isRecording()) - clearScript(); bulk_timer.stop(); } @@ -232,9 +229,6 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev ) c.at( 0 ) = ev->ascii(); // 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 ); } } @@ -261,35 +255,6 @@ void EmulationLayer::onRcvBlock(const QByteArray &s ) bulkEnd(); } -// 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 --------------------------------------------------------------- -- void EmulationLayer::onSelectionBegin(const int x, const int y) { @@ -406,3 +371,4 @@ void EmulationLayer::setColumns(int columns) // Can we put this straight or explain it at least? emit changeColumns(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 @@ -32,7 +32,6 @@ #include #include #include "keytrans.h" -#include "script.h" class EmulationLayer : public QObject { Q_OBJECT @@ -105,22 +104,6 @@ public: void setKeytrans(int no); void setKeytrans(const char * no); - /* 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: WidgetLayer* gui; @@ -156,7 +139,6 @@ private: int bulk_nlcnt; // bulk newline counter char* SelectedText; 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 @@ -286,29 +286,26 @@ void MainWindow::slotNew() { } void MainWindow::slotRecordScript() { -/* if (currentSession()) { - currentSession()->emulationLayer()->startRecording(); + if (currentSession()) { + currentSession()->emulationHandler()->startRecording(); } - */ } void MainWindow::slotSaveScript() { -/* if (currentSession() && currentSession()->emulationLayer()->isRecording()) { + if (currentSession() && currentSession()->emulationHandler()->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(); + currentSession()->emulationHandler()->script()->saveTo(filename); + currentSession()->emulationHandler()->clearScript(); } } - */ } void MainWindow::slotRunScript() { -/* if (currentSession()) { MimeTypes types; QStringList script; @@ -317,10 +314,9 @@ void MainWindow::slotRunScript() { QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); if (!filename.isEmpty()) { Script script(DocLnk(filename).file()); - currentSession()->emulationLayer()->runScript(&script); + currentSession()->emulationHandler()->runScript(&script); } } - */ } void MainWindow::slotConnect() { 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 @@ -7,24 +7,23 @@ Script::Script() { Script::Script(const QString fileName) { QFile file(fileName); - QTextStream stream(&file); - while (!stream.atEnd()) { - appendString(stream.readLine()); - } + m_script = file.readAll(); } void Script::saveTo(const QString fileName) const { QFile file(fileName); file.open(IO_WriteOnly); - file.writeBlock(m_script.ascii(), m_script.length()); + file.writeBlock(m_script); file.close(); } -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 @@ -15,15 +15,15 @@ public: Script(const QString fileName); /* Append a line to the script */ - void appendString(const QString string); + void append(const QByteArray &data); /* Save this script to a file */ void saveTo(const QString fileName) const; /* Return the script's content */ - QString script() const; + QByteArray script() const; protected: - QString m_script; + QByteArray m_script; }; -- cgit v0.9.0.2