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 @@ -1,71 +1,77 @@ #include <qwidget.h> #include <qpushbutton.h> #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) ), this, SLOT(recvEmulation(const char*, int) ) ); m_teEmu->setConnect( true ); m_teEmu->setHistory( TRUE ); 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) ); } void EmulationHandler::recv( const QByteArray& ar) { m_teEmu->onRcvBlock(ar.data(), ar.count() ); } 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; } /* * allocate a new table of colors */ void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { ColorEntry table[TABLE_COLORS]; const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); for (int i = 0; i < TABLE_COLORS; i++ ) { if ( i == 0 || i == 10 ) { table[i].color = fore; }else if ( i == 1 || i == 11 ) { table[i].color = back; table[i].transparent = 0; }else { table[i].color = defaultCt[i].color; } } m_teWid->setColorTable(table ); m_teWid->update(); @@ -124,24 +130,50 @@ QColor EmulationHandler::backColor(int col ) { default: case Profile::White: /* color is white */ co = Qt::black; break; case Profile::Black: co = Qt::white; break; case Profile::Green: qWarning("Background black"); co = Qt::black; break; case Profile::Orange: qWarning("Background black"); co = Qt::black; break; } 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 @@ -8,66 +8,83 @@ /* * Badly ibotty lacks the time to finish * his widget in time.. * Never the less we've to have an EmulationWidget * This is why I'm taking the inferior not cleaned * up TE* KDE STUFF */ /** * This is the layer above the IOLayer* * This nice QObject here will get stuff from * got a slot and a signal * the signal for data * the slot for receiving * it'll set up the widget internally * and manage the communication between * the pre QByteArray world! */ 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 * and a Profile */ EmulationHandler( const Profile&, QWidget* parent, const char* name = 0l ); /** * delete all components */ ~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 ); public slots: void recv( const QByteArray& ); private slots: void recvEmulation( const char*, int len ); private: QFont font( int ); 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 @@ -86,76 +86,73 @@ /* ------------------------------------------------------------------------- */ /* */ /* 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) @@ -211,106 +208,74 @@ void EmulationLayer::onRcvChar(int c) /* */ /* ------------------------------------------------------------------------- */ /*! */ 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(); @@ -385,24 +350,25 @@ void EmulationLayer::setConnect(bool c) */ void EmulationLayer::onImageSizeChange(int lines, int columns) { if (!connected) return; screen[0]->resizeImage(lines,columns); screen[1]->resizeImage(lines,columns); showBulk(); emit ImageSizeChanged(lines,columns); // propagate event to serial line } void EmulationLayer::onHistoryCursorChange(int cursor) { if (!connected) return; scr->setHistCursor(cursor); showBulk(); } 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 @@ -11,49 +11,48 @@ /* -------------------------------------------------------------------------- */ /* */ /* Ported Konsole to Qt/Embedded */ /* */ /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ /* */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* */ /* made to a layer between io_layer and widget */ /* */ /* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ /* */ /* -------------------------------------------------------------------------- */ #ifndef EMULATION_LAYER_H #define EMULATION_LAYER_H #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: EmulationLayer( WidgetLayer* gui ); ~EmulationLayer(); public: virtual void setHistory(bool on); virtual bool history(); public slots: // signals incoming from Widget virtual void onImageSizeChange(int lines, int columns); virtual void onHistoryCursorChange(int cursor); virtual void onKeyPress(QKeyEvent*); virtual void clearSelection(); virtual void onSelectionBegin(const int x, const int y); virtual void onSelectionExtend(const int x, const int y); virtual void setSelection(const bool preserve_line_breaks); @@ -84,80 +83,63 @@ public: * process single char (decode) */ virtual void onRcvChar(int); virtual void setMode (int) = 0; virtual void resetMode(int) = 0; /** * @deprecated use qbytearray instead */ virtual void sendString(const char*) = 0; /** * sends a string to IOLayer * encodes to suit emulation before */ virtual void sendString(const QByteArray&) = 0; 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]' bool connected; // communicate with widget void setCodec(int c); // codec number, 0 = locale, 1=utf8 QTextCodec* codec; QTextCodec* localeCodec; QTextDecoder* decoder; KeyTrans* keytrans; // refreshing related material. // this is localized in the class. private slots: // triggered by timer void showBulk(); private: void bulkNewline(); void bulkStart(); void bulkEnd(); 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 @@ -265,83 +265,79 @@ MainWindow::~MainWindow() { MetaFactory* MainWindow::factory() { return m_factory; } Session* MainWindow::currentSession() { return m_curSession; } QList<Session> MainWindow::sessions() { return m_sessions; } void MainWindow::slotNew() { ProfileEditorDialog dlg(factory() ); dlg.showMaximized(); int ret = dlg.exec(); 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(), QObject::tr("Failed"), QObject::tr("Connecting failed for this session.")); else { m_connect->setEnabled( false ); m_disconnect->setEnabled( true ); } } } void MainWindow::slotDisconnect() { if ( currentSession() ) { currentSession()->layer()->close(); m_connect->setEnabled( true ); m_disconnect->setEnabled( false ); } } void MainWindow::slotTerminate() { 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 @@ -1,30 +1,29 @@ #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()); - } + 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 @@ -1,30 +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); + 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 */ |