-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 @@ -3,19 +3,20 @@ #include "TEWidget.h" #include "TEmuVt102.h" #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 ); connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), this, SIGNAL(changeSize(int, int) ) ); connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), @@ -25,15 +26,18 @@ EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const c load( prof ); } 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"); setColor( foreColor(num), backColor(num) ); m_teWid->setBackgroundColor(backColor(num) ); } @@ -42,12 +46,14 @@ void EmulationHandler::recv( const QByteArray& ar) { } void EmulationHandler::recvEmulation(const char* src, int len ) { QByteArray ar(len); memcpy(ar.data(), src, sizeof(char) * len ); + if (isRecording()) + m_script->append(ar); emit send(ar); } QWidget* EmulationHandler::widget() { return m_teWid; } /* @@ -142,6 +148,32 @@ QColor EmulationHandler::backColor(int col ) { return co; } 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 @@ -26,12 +26,13 @@ class Profile; class QWidget; class QPushButton; class TEWidget; class TEmulation; class QFont; +class Script; class EmulationHandler : public QObject { Q_OBJECT public: /** * simple c'tor the parent of the TEWdiget * and a name @@ -45,12 +46,28 @@ public: ~EmulationHandler(); void load( const Profile& ); 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& ); void changeSize(int rows, int cols ); @@ -64,10 +81,10 @@ private: QColor foreColor(int ); QColor backColor(int ); 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 @@ -104,13 +104,12 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui ) screen[1] = new Screen(gui->lines(),gui->columns()); scr = screen[0]; 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 ) ), this,SLOT( onImageSizeChange( int, int ) ) ); QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), this,SLOT( historyCursorChange( int ) ) ); @@ -130,14 +129,12 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui ) */ EmulationLayer::~EmulationLayer() { delete screen[0]; delete screen[1]; - if (isRecording()) - clearScript(); bulk_timer.stop(); } /*! change between primary and alternate screen */ @@ -229,15 +226,12 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev ) else if (ev->ascii()>0) { QByteArray c = QByteArray( 1 ); 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 ); } } // Unblocking, Byte to Unicode translation --------------------------------- -- @@ -258,41 +252,12 @@ void EmulationLayer::onRcvBlock(const QByteArray &s ) onRcvChar(result[j].unicode()); if (s[i] == '\n') bulkNewline(); } 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) { if (!connected) return; scr->setSelBeginXY(x,y); showBulk(); @@ -403,6 +368,7 @@ void EmulationLayer::onHistoryCursorChange(int cursor) void EmulationLayer::setColumns(int columns) { //FIXME: this goes strange ways. // 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 @@ -29,13 +29,12 @@ #include "widget_layer.h" #include "screen.h" #include <qtimer.h> #include <stdio.h> #include <qtextcodec.h> #include "keytrans.h" -#include "script.h" class EmulationLayer : public QObject { Q_OBJECT public: @@ -102,28 +101,12 @@ public: virtual void setConnect(bool r); void setColumns(int columns); 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; Screen* scr; // referes to one `screen' Screen* screen[2]; // 0 = primary, 1 = alternate void setScreen(int n); // set `scr' to `screen[n]' @@ -153,11 +136,10 @@ private: private: QTimer bulk_timer; int bulk_nlcnt; // bulk newline counter char* SelectedText; int bulk_incnt; // bulk counter - Script *m_script; }; #endif // ifndef EMULATION_H 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 @@ -283,47 +283,43 @@ void MainWindow::slotNew() { if ( ret == QDialog::Accepted ) { create( dlg.profile() ); } } 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; 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); + currentSession()->emulationHandler()->runScript(&script); } } - */ } void MainWindow::slotConnect() { if ( currentSession() ) { bool ret = currentSession()->layer()->open(); if(!ret) QMessageBox::warning(currentSession()->widgetStack(), 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 @@ -4,27 +4,26 @@ 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 @@ -12,19 +12,19 @@ public: Script(); /* Load a script from a text file */ 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; }; #endif /* CONSOLE_SCRIPT_H */ |