Diffstat (limited to 'noncore/apps/opie-console/emulation_layer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-console/emulation_layer.cpp | 36 |
1 files changed, 36 insertions, 0 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 @@ -86,73 +86,76 @@ /* ------------------------------------------------------------------------- */ /* */ /* EmulationLayer */ /* */ /* ------------------------------------------------------------------------- */ #define CNTL(c) ((c)-'@') /*! */ EmulationLayer::EmulationLayer( WidgetLayer* gui ) : decoder((QTextDecoder*)NULL) { this->gui = gui; screen[0] = new Screen(gui->lines(),gui->columns()); 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 ) ) ); QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), this,SLOT( onKeyPress( QKeyEvent* ) ) ); QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), this,SLOT( onSelectionBegin( const int, const int ) ) ); QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), this,SLOT( onSelectionExtend( const int,const int ) ) ); QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), this,SLOT( setSelection( const bool ) ) ); QObject::connect(gui,SIGNAL( selectionCleared() ), this,SLOT( clearSelection() ) ); } /*! */ EmulationLayer::~EmulationLayer() { delete screen[0]; delete screen[1]; + if (isRecording()) + clearScript(); bulk_timer.stop(); } /*! change between primary and alternate screen */ void EmulationLayer::setScreen(int n) { scr = screen[n&1]; } void EmulationLayer::setHistory(bool on) { screen[0]->setScroll(on); if (!connected) return; showBulk(); } bool EmulationLayer::history() { return screen[0]->hasScroll(); } void EmulationLayer::setCodec(int c) @@ -207,74 +210,107 @@ void EmulationLayer::onRcvChar(int c) /* Keyboard Handling */ /* */ /* ------------------------------------------------------------------------- */ /*! */ void EmulationLayer::onKeyPress( QKeyEvent* ev ) { if (!connected) return; // someone else gets the keys if (scr->getHistCursor() != scr->getHistLines()); scr->setHistCursor(scr->getHistLines()); if (!ev->text().isEmpty()) { // A block of text // Note that the text is proper unicode. // We should do a conversion here, but since this // routine will never be used, we simply emit plain ascii. sendString( ev->text().ascii() ); //,ev->text().length()); } 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 --------------------------------- -- /* We are doing code conversion from locale to unicode first. */ void EmulationLayer::onRcvBlock(const QByteArray &s ) { bulkStart(); bulk_incnt += 1; for (int i = 0; i < s.size(); i++) { //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? QString result = decoder->toUnicode(&s[i],1); int reslen = result.length(); for (int j = 0; j < reslen; j++) 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(); } void EmulationLayer::onSelectionExtend(const int x, const int y) { if (!connected) return; scr->setSelExtentXY(x,y); showBulk(); } void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { if (!connected) return; QString t = scr->getSelText(preserve_line_breaks); if (!t.isNull()) gui->setSelection(t); } void EmulationLayer::clearSelection() { if (!connected) return; scr->clearSelection(); showBulk(); |