author | wazlaf <wazlaf> | 2002-10-20 14:53:08 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-10-20 14:53:08 (UTC) |
commit | 18ba3be9ca69c42476e310649e3068d2d5f8a03b (patch) (unidiff) | |
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,95 +1,101 @@ | |||
1 | #include <qwidget.h> | 1 | #include <qwidget.h> |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | 3 | ||
4 | #include "TEWidget.h" | 4 | #include "TEWidget.h" |
5 | #include "TEmuVt102.h" | 5 | #include "TEmuVt102.h" |
6 | 6 | ||
7 | #include "profile.h" | 7 | #include "profile.h" |
8 | #include "emulation_handler.h" | 8 | #include "emulation_handler.h" |
9 | 9 | #include "script.h" | |
10 | 10 | ||
11 | EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) | 11 | EmulationHandler::EmulationHandler( const Profile& prof, QWidget* parent,const char* name ) |
12 | : QObject(0, name ) | 12 | : QObject(0, name ) |
13 | { | 13 | { |
14 | m_teWid = new TEWidget( parent, "TerminalMain"); | 14 | m_teWid = new TEWidget( parent, "TerminalMain"); |
15 | m_teWid->setMinimumSize(150, 70 ); | 15 | m_teWid->setMinimumSize(150, 70 ); |
16 | m_script = 0; | ||
16 | parent->resize( m_teWid->calcSize(80, 24 ) ); | 17 | parent->resize( m_teWid->calcSize(80, 24 ) ); |
17 | m_teEmu = new TEmuVt102(m_teWid ); | 18 | m_teEmu = new TEmuVt102(m_teWid ); |
18 | 19 | ||
19 | connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), | 20 | connect(m_teEmu,SIGNAL(ImageSizeChanged(int, int) ), |
20 | this, SIGNAL(changeSize(int, int) ) ); | 21 | this, SIGNAL(changeSize(int, int) ) ); |
21 | connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), | 22 | connect(m_teEmu, SIGNAL(sndBlock(const char*, int) ), |
22 | this, SLOT(recvEmulation(const char*, int) ) ); | 23 | this, SLOT(recvEmulation(const char*, int) ) ); |
23 | m_teEmu->setConnect( true ); | 24 | m_teEmu->setConnect( true ); |
24 | m_teEmu->setHistory( TRUE ); | 25 | m_teEmu->setHistory( TRUE ); |
25 | load( prof ); | 26 | load( prof ); |
26 | 27 | ||
27 | 28 | ||
28 | 29 | ||
29 | } | 30 | } |
30 | EmulationHandler::~EmulationHandler() { | 31 | EmulationHandler::~EmulationHandler() { |
32 | if (isRecording()) | ||
33 | clearScript(); | ||
31 | delete m_teEmu; | 34 | delete m_teEmu; |
32 | delete m_teWid; | 35 | delete m_teWid; |
33 | } | 36 | } |
37 | |||
34 | void EmulationHandler::load( const Profile& prof) { | 38 | void EmulationHandler::load( const Profile& prof) { |
35 | m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); | 39 | m_teWid->setVTFont( font( prof.readNumEntry("Font") ) ); |
36 | int num = prof.readNumEntry("Color"); | 40 | int num = prof.readNumEntry("Color"); |
37 | setColor( foreColor(num), backColor(num) ); | 41 | setColor( foreColor(num), backColor(num) ); |
38 | m_teWid->setBackgroundColor(backColor(num) ); | 42 | m_teWid->setBackgroundColor(backColor(num) ); |
39 | } | 43 | } |
40 | void EmulationHandler::recv( const QByteArray& ar) { | 44 | void EmulationHandler::recv( const QByteArray& ar) { |
41 | m_teEmu->onRcvBlock(ar.data(), ar.count() ); | 45 | m_teEmu->onRcvBlock(ar.data(), ar.count() ); |
42 | } | 46 | } |
43 | void EmulationHandler::recvEmulation(const char* src, int len ) { | 47 | void EmulationHandler::recvEmulation(const char* src, int len ) { |
44 | QByteArray ar(len); | 48 | QByteArray ar(len); |
45 | 49 | ||
46 | memcpy(ar.data(), src, sizeof(char) * len ); | 50 | memcpy(ar.data(), src, sizeof(char) * len ); |
47 | 51 | ||
52 | if (isRecording()) | ||
53 | m_script->append(ar); | ||
48 | emit send(ar); | 54 | emit send(ar); |
49 | } | 55 | } |
50 | QWidget* EmulationHandler::widget() { | 56 | QWidget* EmulationHandler::widget() { |
51 | return m_teWid; | 57 | return m_teWid; |
52 | } | 58 | } |
53 | /* | 59 | /* |
54 | * allocate a new table of colors | 60 | * allocate a new table of colors |
55 | */ | 61 | */ |
56 | void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { | 62 | void EmulationHandler::setColor( const QColor& fore, const QColor& back ) { |
57 | ColorEntry table[TABLE_COLORS]; | 63 | ColorEntry table[TABLE_COLORS]; |
58 | const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); | 64 | const ColorEntry *defaultCt = m_teWid->getdefaultColorTable(); |
59 | 65 | ||
60 | for (int i = 0; i < TABLE_COLORS; i++ ) { | 66 | for (int i = 0; i < TABLE_COLORS; i++ ) { |
61 | if ( i == 0 || i == 10 ) { | 67 | if ( i == 0 || i == 10 ) { |
62 | table[i].color = fore; | 68 | table[i].color = fore; |
63 | }else if ( i == 1 || i == 11 ) { | 69 | }else if ( i == 1 || i == 11 ) { |
64 | table[i].color = back; | 70 | table[i].color = back; |
65 | table[i].transparent = 0; | 71 | table[i].transparent = 0; |
66 | }else { | 72 | }else { |
67 | table[i].color = defaultCt[i].color; | 73 | table[i].color = defaultCt[i].color; |
68 | } | 74 | } |
69 | } | 75 | } |
70 | m_teWid->setColorTable(table ); | 76 | m_teWid->setColorTable(table ); |
71 | m_teWid->update(); | 77 | m_teWid->update(); |
72 | } | 78 | } |
73 | QFont EmulationHandler::font( int id ) { | 79 | QFont EmulationHandler::font( int id ) { |
74 | QString name; | 80 | QString name; |
75 | int size = 0; | 81 | int size = 0; |
76 | switch(id ) { | 82 | switch(id ) { |
77 | default: // fall through | 83 | default: // fall through |
78 | case 0: | 84 | case 0: |
79 | name = QString::fromLatin1("Micro"); | 85 | name = QString::fromLatin1("Micro"); |
80 | size = 4; | 86 | size = 4; |
81 | break; | 87 | break; |
82 | case 1: | 88 | case 1: |
83 | name = QString::fromLatin1("Fixed"); | 89 | name = QString::fromLatin1("Fixed"); |
84 | size = 7; | 90 | size = 7; |
85 | break; | 91 | break; |
86 | case 2: | 92 | case 2: |
87 | name = QString::fromLatin1("Fixed"); | 93 | name = QString::fromLatin1("Fixed"); |
88 | size = 12; | 94 | size = 12; |
89 | break; | 95 | break; |
90 | } | 96 | } |
91 | QFont font(name, size, QFont::Normal ); | 97 | QFont font(name, size, QFont::Normal ); |
92 | font.setFixedPitch(TRUE ); | 98 | font.setFixedPitch(TRUE ); |
93 | return font; | 99 | return font; |
94 | } | 100 | } |
95 | QColor EmulationHandler::foreColor(int col) { | 101 | QColor EmulationHandler::foreColor(int col) { |
@@ -100,48 +106,74 @@ QColor EmulationHandler::foreColor(int col) { | |||
100 | case Profile::White: | 106 | case Profile::White: |
101 | /* color is black */ | 107 | /* color is black */ |
102 | co = Qt::white; | 108 | co = Qt::white; |
103 | break; | 109 | break; |
104 | case Profile::Black: | 110 | case Profile::Black: |
105 | co = Qt::black; | 111 | co = Qt::black; |
106 | break; | 112 | break; |
107 | case Profile::Green: | 113 | case Profile::Green: |
108 | qWarning("Foreground green"); | 114 | qWarning("Foreground green"); |
109 | co = Qt::green; | 115 | co = Qt::green; |
110 | break; | 116 | break; |
111 | case Profile::Orange: | 117 | case Profile::Orange: |
112 | qWarning("Foreground orange"); | 118 | qWarning("Foreground orange"); |
113 | // FIXME needs better color here | 119 | // FIXME needs better color here |
114 | co = Qt::darkYellow; | 120 | co = Qt::darkYellow; |
115 | break; | 121 | break; |
116 | } | 122 | } |
117 | 123 | ||
118 | return co; | 124 | return co; |
119 | } | 125 | } |
120 | QColor EmulationHandler::backColor(int col ) { | 126 | QColor EmulationHandler::backColor(int col ) { |
121 | QColor co; | 127 | QColor co; |
122 | /* we need to switch it */ | 128 | /* we need to switch it */ |
123 | switch( col ) { | 129 | switch( col ) { |
124 | default: | 130 | default: |
125 | case Profile::White: | 131 | case Profile::White: |
126 | /* color is white */ | 132 | /* color is white */ |
127 | co = Qt::black; | 133 | co = Qt::black; |
128 | break; | 134 | break; |
129 | case Profile::Black: | 135 | case Profile::Black: |
130 | co = Qt::white; | 136 | co = Qt::white; |
131 | break; | 137 | break; |
132 | case Profile::Green: | 138 | case Profile::Green: |
133 | qWarning("Background black"); | 139 | qWarning("Background black"); |
134 | co = Qt::black; | 140 | co = Qt::black; |
135 | break; | 141 | break; |
136 | case Profile::Orange: | 142 | case Profile::Orange: |
137 | qWarning("Background black"); | 143 | qWarning("Background black"); |
138 | co = Qt::black; | 144 | co = Qt::black; |
139 | break; | 145 | break; |
140 | } | 146 | } |
141 | 147 | ||
142 | return co; | 148 | return co; |
143 | } | 149 | } |
144 | 150 | ||
145 | QPushButton* EmulationHandler::cornerButton() { | 151 | QPushButton* EmulationHandler::cornerButton() { |
146 | return m_teWid->cornerButton(); | 152 | return m_teWid->cornerButton(); |
147 | } | 153 | } |
154 | |||
155 | |||
156 | Script *EmulationHandler::script() { | ||
157 | return m_script; | ||
158 | } | ||
159 | |||
160 | bool EmulationHandler::isRecording() { | ||
161 | return (m_script != 0); | ||
162 | } | ||
163 | |||
164 | void EmulationHandler::startRecording() { | ||
165 | if (!isRecording()) | ||
166 | m_script = new Script(); | ||
167 | } | ||
168 | |||
169 | void EmulationHandler::clearScript() { | ||
170 | if (isRecording()) { | ||
171 | delete m_script; | ||
172 | m_script = 0; | ||
173 | } | ||
174 | } | ||
175 | |||
176 | void EmulationHandler::runScript(const Script *script) { | ||
177 | emit send(script->script()); | ||
178 | } | ||
179 | |||
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 | |||
@@ -1,73 +1,90 @@ | |||
1 | #ifndef OPIE_EMULATION_HANDLER_H | 1 | #ifndef OPIE_EMULATION_HANDLER_H |
2 | #define OPIE_EMULATION_HANDLER_H | 2 | #define OPIE_EMULATION_HANDLER_H |
3 | 3 | ||
4 | #include <qobject.h> | 4 | #include <qobject.h> |
5 | #include <qcolor.h> | 5 | #include <qcolor.h> |
6 | #include <qcstring.h> | 6 | #include <qcstring.h> |
7 | 7 | ||
8 | /* | 8 | /* |
9 | * Badly ibotty lacks the time to finish | 9 | * Badly ibotty lacks the time to finish |
10 | * his widget in time.. | 10 | * his widget in time.. |
11 | * Never the less we've to have an EmulationWidget | 11 | * Never the less we've to have an EmulationWidget |
12 | * This is why I'm taking the inferior not cleaned | 12 | * This is why I'm taking the inferior not cleaned |
13 | * up TE* KDE STUFF | 13 | * up TE* KDE STUFF |
14 | */ | 14 | */ |
15 | 15 | ||
16 | /** | 16 | /** |
17 | * This is the layer above the IOLayer* | 17 | * This is the layer above the IOLayer* |
18 | * This nice QObject here will get stuff from | 18 | * This nice QObject here will get stuff from |
19 | * got a slot and a signal | 19 | * got a slot and a signal |
20 | * the signal for data | 20 | * the signal for data |
21 | * the slot for receiving | 21 | * the slot for receiving |
22 | * it'll set up the widget internally | 22 | * it'll set up the widget internally |
23 | * and manage the communication between | 23 | * and manage the communication between |
24 | * the pre QByteArray world! | 24 | * the pre QByteArray world! |
25 | */ | 25 | */ |
26 | class Profile; | 26 | class Profile; |
27 | class QWidget; | 27 | class QWidget; |
28 | class QPushButton; | 28 | class QPushButton; |
29 | class TEWidget; | 29 | class TEWidget; |
30 | class TEmulation; | 30 | class TEmulation; |
31 | class QFont; | 31 | class QFont; |
32 | class Script; | ||
32 | class EmulationHandler : public QObject { | 33 | class EmulationHandler : public QObject { |
33 | Q_OBJECT | 34 | Q_OBJECT |
34 | public: | 35 | public: |
35 | /** | 36 | /** |
36 | * simple c'tor the parent of the TEWdiget | 37 | * simple c'tor the parent of the TEWdiget |
37 | * and a name | 38 | * and a name |
38 | * and a Profile | 39 | * and a Profile |
39 | */ | 40 | */ |
40 | EmulationHandler( const Profile&, QWidget* parent, const char* name = 0l ); | 41 | EmulationHandler( const Profile&, QWidget* parent, const char* name = 0l ); |
41 | 42 | ||
42 | /** | 43 | /** |
43 | * delete all components | 44 | * delete all components |
44 | */ | 45 | */ |
45 | ~EmulationHandler(); | 46 | ~EmulationHandler(); |
46 | 47 | ||
47 | void load( const Profile& ); | 48 | void load( const Profile& ); |
48 | QWidget* widget(); | 49 | QWidget* widget(); |
49 | void setColor( const QColor& fore, const QColor& back ); | 50 | void setColor( const QColor& fore, const QColor& back ); |
50 | QPushButton* cornerButton(); | 51 | QPushButton* cornerButton(); |
52 | |||
53 | /* Scripts */ | ||
54 | /* Create a new script and record all typed characters */ | ||
55 | void startRecording(); | ||
56 | |||
57 | /* Return whether we are currently recording a script */ | ||
58 | bool isRecording(); | ||
59 | |||
60 | /* Return the current script (or NULL) */ | ||
61 | Script *script(); | ||
62 | |||
63 | /* Stop recording and remove the current script from memory */ | ||
64 | void clearScript(); | ||
65 | |||
66 | /* Run a script by forwarding its keys to the EmulationLayer */ | ||
67 | void runScript(const Script *); | ||
51 | 68 | ||
52 | signals: | 69 | signals: |
53 | void send( const QByteArray& ); | 70 | void send( const QByteArray& ); |
54 | void changeSize(int rows, int cols ); | 71 | void changeSize(int rows, int cols ); |
55 | 72 | ||
56 | 73 | ||
57 | public slots: | 74 | public slots: |
58 | void recv( const QByteArray& ); | 75 | void recv( const QByteArray& ); |
59 | 76 | ||
60 | private slots: | 77 | private slots: |
61 | void recvEmulation( const char*, int len ); | 78 | void recvEmulation( const char*, int len ); |
62 | private: | 79 | private: |
63 | QFont font( int ); | 80 | QFont font( int ); |
64 | QColor foreColor(int ); | 81 | QColor foreColor(int ); |
65 | QColor backColor(int ); | 82 | QColor backColor(int ); |
66 | 83 | ||
67 | private: | 84 | private: |
68 | TEWidget* m_teWid; | 85 | TEWidget* m_teWid; |
69 | TEmulation* m_teEmu; | 86 | TEmulation* m_teEmu; |
70 | 87 | Script * m_script; | |
71 | }; | 88 | }; |
72 | 89 | ||
73 | #endif | 90 | #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 | |||
@@ -62,124 +62,121 @@ | |||
62 | well as individual characters typed. | 62 | well as individual characters typed. |
63 | (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). | 63 | (BULK_TIMEOUT < 1000 / max characters received from keyboard per second). |
64 | 64 | ||
65 | Additionally, we trigger refreshing by newlines comming in to make visual | 65 | Additionally, we trigger refreshing by newlines comming in to make visual |
66 | snapshots of lists as produced by `cat', `ls' and likely programs, thereby | 66 | snapshots of lists as produced by `cat', `ls' and likely programs, thereby |
67 | producing the illusion of a permanent and immediate display operation. | 67 | producing the illusion of a permanent and immediate display operation. |
68 | 68 | ||
69 | As a sort of catch-all needed for cases where none of the above | 69 | As a sort of catch-all needed for cases where none of the above |
70 | conditions catch, the screen refresh is also triggered by a count | 70 | conditions catch, the screen refresh is also triggered by a count |
71 | of incoming bulks (`bulk_incnt'). | 71 | of incoming bulks (`bulk_incnt'). |
72 | */ | 72 | */ |
73 | 73 | ||
74 | /* FIXME | 74 | /* FIXME |
75 | - evtl. the bulk operations could be made more transparent. | 75 | - evtl. the bulk operations could be made more transparent. |
76 | */ | 76 | */ |
77 | 77 | ||
78 | #include "emulation_layer.h" | 78 | #include "emulation_layer.h" |
79 | #include "widget_layer.h" | 79 | #include "widget_layer.h" |
80 | #include "screen.h" | 80 | #include "screen.h" |
81 | #include <stdio.h> | 81 | #include <stdio.h> |
82 | #include <stdlib.h> | 82 | #include <stdlib.h> |
83 | #include <unistd.h> | 83 | #include <unistd.h> |
84 | #include <qkeycode.h> | 84 | #include <qkeycode.h> |
85 | 85 | ||
86 | 86 | ||
87 | /* ------------------------------------------------------------------------- */ | 87 | /* ------------------------------------------------------------------------- */ |
88 | /* */ | 88 | /* */ |
89 | /* EmulationLayer */ | 89 | /* EmulationLayer */ |
90 | /* */ | 90 | /* */ |
91 | /* ------------------------------------------------------------------------- */ | 91 | /* ------------------------------------------------------------------------- */ |
92 | 92 | ||
93 | #define CNTL(c) ((c)-'@') | 93 | #define CNTL(c) ((c)-'@') |
94 | 94 | ||
95 | /*! | 95 | /*! |
96 | */ | 96 | */ |
97 | 97 | ||
98 | EmulationLayer::EmulationLayer( WidgetLayer* gui ) | 98 | EmulationLayer::EmulationLayer( WidgetLayer* gui ) |
99 | : decoder((QTextDecoder*)NULL) | 99 | : decoder((QTextDecoder*)NULL) |
100 | { | 100 | { |
101 | this->gui = gui; | 101 | this->gui = gui; |
102 | 102 | ||
103 | screen[0] = new Screen(gui->lines(),gui->columns()); | 103 | screen[0] = new Screen(gui->lines(),gui->columns()); |
104 | screen[1] = new Screen(gui->lines(),gui->columns()); | 104 | screen[1] = new Screen(gui->lines(),gui->columns()); |
105 | scr = screen[0]; | 105 | scr = screen[0]; |
106 | 106 | ||
107 | bulk_nlcnt = 0; // reset bulk newline counter | 107 | bulk_nlcnt = 0; // reset bulk newline counter |
108 | bulk_incnt = 0; // reset bulk counter | 108 | bulk_incnt = 0; // reset bulk counter |
109 | connected = FALSE; | 109 | connected = FALSE; |
110 | m_script = 0; | ||
111 | 110 | ||
112 | QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); | 111 | QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); |
113 | QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), | 112 | QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), |
114 | this,SLOT( onImageSizeChange( int, int ) ) ); | 113 | this,SLOT( onImageSizeChange( int, int ) ) ); |
115 | QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), | 114 | QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), |
116 | this,SLOT( historyCursorChange( int ) ) ); | 115 | this,SLOT( historyCursorChange( int ) ) ); |
117 | QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), | 116 | QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), |
118 | this,SLOT( onKeyPress( QKeyEvent* ) ) ); | 117 | this,SLOT( onKeyPress( QKeyEvent* ) ) ); |
119 | QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), | 118 | QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), |
120 | this,SLOT( onSelectionBegin( const int, const int ) ) ); | 119 | this,SLOT( onSelectionBegin( const int, const int ) ) ); |
121 | QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), | 120 | QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), |
122 | this,SLOT( onSelectionExtend( const int,const int ) ) ); | 121 | this,SLOT( onSelectionExtend( const int,const int ) ) ); |
123 | QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), | 122 | QObject::connect(gui,SIGNAL( selectionEnd( const bool ) ), |
124 | this,SLOT( setSelection( const bool ) ) ); | 123 | this,SLOT( setSelection( const bool ) ) ); |
125 | QObject::connect(gui,SIGNAL( selectionCleared() ), | 124 | QObject::connect(gui,SIGNAL( selectionCleared() ), |
126 | this,SLOT( clearSelection() ) ); | 125 | this,SLOT( clearSelection() ) ); |
127 | } | 126 | } |
128 | 127 | ||
129 | /*! | 128 | /*! |
130 | */ | 129 | */ |
131 | 130 | ||
132 | EmulationLayer::~EmulationLayer() | 131 | EmulationLayer::~EmulationLayer() |
133 | { | 132 | { |
134 | delete screen[0]; | 133 | delete screen[0]; |
135 | delete screen[1]; | 134 | delete screen[1]; |
136 | if (isRecording()) | ||
137 | clearScript(); | ||
138 | bulk_timer.stop(); | 135 | bulk_timer.stop(); |
139 | } | 136 | } |
140 | 137 | ||
141 | /*! change between primary and alternate screen | 138 | /*! change between primary and alternate screen |
142 | */ | 139 | */ |
143 | 140 | ||
144 | void EmulationLayer::setScreen(int n) | 141 | void EmulationLayer::setScreen(int n) |
145 | { | 142 | { |
146 | scr = screen[n&1]; | 143 | scr = screen[n&1]; |
147 | } | 144 | } |
148 | 145 | ||
149 | void EmulationLayer::setHistory(bool on) | 146 | void EmulationLayer::setHistory(bool on) |
150 | { | 147 | { |
151 | screen[0]->setScroll(on); | 148 | screen[0]->setScroll(on); |
152 | if (!connected) return; | 149 | if (!connected) return; |
153 | showBulk(); | 150 | showBulk(); |
154 | } | 151 | } |
155 | 152 | ||
156 | bool EmulationLayer::history() | 153 | bool EmulationLayer::history() |
157 | { | 154 | { |
158 | return screen[0]->hasScroll(); | 155 | return screen[0]->hasScroll(); |
159 | } | 156 | } |
160 | 157 | ||
161 | void EmulationLayer::setCodec(int c) | 158 | void EmulationLayer::setCodec(int c) |
162 | { | 159 | { |
163 | //FIXME: check whether we have to free codec | 160 | //FIXME: check whether we have to free codec |
164 | codec = c ? QTextCodec::codecForName("utf8") | 161 | codec = c ? QTextCodec::codecForName("utf8") |
165 | : QTextCodec::codecForLocale(); | 162 | : QTextCodec::codecForLocale(); |
166 | if (decoder) delete decoder; | 163 | if (decoder) delete decoder; |
167 | decoder = codec->makeDecoder(); | 164 | decoder = codec->makeDecoder(); |
168 | } | 165 | } |
169 | 166 | ||
170 | void EmulationLayer::setKeytrans(int no) | 167 | void EmulationLayer::setKeytrans(int no) |
171 | { | 168 | { |
172 | keytrans = KeyTrans::find(no); | 169 | keytrans = KeyTrans::find(no); |
173 | } | 170 | } |
174 | 171 | ||
175 | void EmulationLayer::setKeytrans(const char * no) | 172 | void EmulationLayer::setKeytrans(const char * no) |
176 | { | 173 | { |
177 | keytrans = KeyTrans::find(no); | 174 | keytrans = KeyTrans::find(no); |
178 | } | 175 | } |
179 | 176 | ||
180 | // Interpreting Codes --------------------------------------------------------- | 177 | // Interpreting Codes --------------------------------------------------------- |
181 | 178 | ||
182 | /* | 179 | /* |
183 | This section deals with decoding the incoming character stream. | 180 | This section deals with decoding the incoming character stream. |
184 | Decoding means here, that the stream is first seperated into `tokens' | 181 | Decoding means here, that the stream is first seperated into `tokens' |
185 | which are then mapped to a `meaning' provided as operations by the | 182 | which are then mapped to a `meaning' provided as operations by the |
@@ -187,154 +184,122 @@ void EmulationLayer::setKeytrans(const char * no) | |||
187 | */ | 184 | */ |
188 | 185 | ||
189 | /*! | 186 | /*! |
190 | */ | 187 | */ |
191 | 188 | ||
192 | void EmulationLayer::onRcvChar(int c) | 189 | void EmulationLayer::onRcvChar(int c) |
193 | // process application unicode input to terminal | 190 | // process application unicode input to terminal |
194 | // this is a trivial scanner | 191 | // this is a trivial scanner |
195 | { | 192 | { |
196 | c &= 0xff; | 193 | c &= 0xff; |
197 | switch (c) | 194 | switch (c) |
198 | { | 195 | { |
199 | case '\b' : scr->BackSpace(); break; | 196 | case '\b' : scr->BackSpace(); break; |
200 | case '\t' : scr->Tabulate(); break; | 197 | case '\t' : scr->Tabulate(); break; |
201 | case '\n' : scr->NewLine(); break; | 198 | case '\n' : scr->NewLine(); break; |
202 | case '\r' : scr->Return(); break; | 199 | case '\r' : scr->Return(); break; |
203 | case 0x07 : gui->bell(); break; | 200 | case 0x07 : gui->bell(); break; |
204 | default : scr->ShowCharacter(c); break; | 201 | default : scr->ShowCharacter(c); break; |
205 | }; | 202 | }; |
206 | } | 203 | } |
207 | 204 | ||
208 | /* ------------------------------------------------------------------------- */ | 205 | /* ------------------------------------------------------------------------- */ |
209 | /* */ | 206 | /* */ |
210 | /* Keyboard Handling */ | 207 | /* Keyboard Handling */ |
211 | /* */ | 208 | /* */ |
212 | /* ------------------------------------------------------------------------- */ | 209 | /* ------------------------------------------------------------------------- */ |
213 | 210 | ||
214 | /*! | 211 | /*! |
215 | */ | 212 | */ |
216 | 213 | ||
217 | void EmulationLayer::onKeyPress( QKeyEvent* ev ) | 214 | void EmulationLayer::onKeyPress( QKeyEvent* ev ) |
218 | { | 215 | { |
219 | if (!connected) return; // someone else gets the keys | 216 | if (!connected) return; // someone else gets the keys |
220 | if (scr->getHistCursor() != scr->getHistLines()); | 217 | if (scr->getHistCursor() != scr->getHistLines()); |
221 | scr->setHistCursor(scr->getHistLines()); | 218 | scr->setHistCursor(scr->getHistLines()); |
222 | if (!ev->text().isEmpty()) | 219 | if (!ev->text().isEmpty()) |
223 | { // A block of text | 220 | { // A block of text |
224 | // Note that the text is proper unicode. | 221 | // Note that the text is proper unicode. |
225 | // We should do a conversion here, but since this | 222 | // We should do a conversion here, but since this |
226 | // routine will never be used, we simply emit plain ascii. | 223 | // routine will never be used, we simply emit plain ascii. |
227 | sendString( ev->text().ascii() ); //,ev->text().length()); | 224 | sendString( ev->text().ascii() ); //,ev->text().length()); |
228 | } | 225 | } |
229 | else if (ev->ascii()>0) | 226 | else if (ev->ascii()>0) |
230 | { | 227 | { |
231 | QByteArray c = QByteArray( 1 ); | 228 | QByteArray c = QByteArray( 1 ); |
232 | c.at( 0 ) = ev->ascii(); | 229 | c.at( 0 ) = ev->ascii(); |
233 | // ibot: qbytearray is emited not char* | 230 | // ibot: qbytearray is emited not char* |
234 | 231 | ||
235 | /* Are we currently recording a script? If so, store the typed character */ | ||
236 | if (isRecording()) | ||
237 | m_script->appendString(ev->text()); | ||
238 | emit sndBlock( (QByteArray) c ); | 232 | emit sndBlock( (QByteArray) c ); |
239 | } | 233 | } |
240 | } | 234 | } |
241 | 235 | ||
242 | // Unblocking, Byte to Unicode translation --------------------------------- -- | 236 | // Unblocking, Byte to Unicode translation --------------------------------- -- |
243 | 237 | ||
244 | /* | 238 | /* |
245 | We are doing code conversion from locale to unicode first. | 239 | We are doing code conversion from locale to unicode first. |
246 | */ | 240 | */ |
247 | 241 | ||
248 | void EmulationLayer::onRcvBlock(const QByteArray &s ) | 242 | void EmulationLayer::onRcvBlock(const QByteArray &s ) |
249 | { | 243 | { |
250 | bulkStart(); | 244 | bulkStart(); |
251 | bulk_incnt += 1; | 245 | bulk_incnt += 1; |
252 | for (int i = 0; i < s.size(); i++) | 246 | for (int i = 0; i < s.size(); i++) |
253 | { | 247 | { |
254 | //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? | 248 | //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? |
255 | QString result = decoder->toUnicode(&s[i],1); | 249 | QString result = decoder->toUnicode(&s[i],1); |
256 | int reslen = result.length(); | 250 | int reslen = result.length(); |
257 | for (int j = 0; j < reslen; j++) | 251 | for (int j = 0; j < reslen; j++) |
258 | onRcvChar(result[j].unicode()); | 252 | onRcvChar(result[j].unicode()); |
259 | if (s[i] == '\n') bulkNewline(); | 253 | if (s[i] == '\n') bulkNewline(); |
260 | } | 254 | } |
261 | bulkEnd(); | 255 | bulkEnd(); |
262 | } | 256 | } |
263 | 257 | ||
264 | // Scripts ----------------------------------------------------------------- -- | ||
265 | |||
266 | |||
267 | Script *EmulationLayer::script() { | ||
268 | return m_script; | ||
269 | } | ||
270 | |||
271 | bool EmulationLayer::isRecording() { | ||
272 | return (m_script != 0); | ||
273 | } | ||
274 | |||
275 | void EmulationLayer::startRecording() { | ||
276 | if (!isRecording()) | ||
277 | m_script = new Script(); | ||
278 | } | ||
279 | |||
280 | void EmulationLayer::clearScript() { | ||
281 | if (isRecording()) { | ||
282 | |||
283 | } | ||
284 | } | ||
285 | |||
286 | void EmulationLayer::runScript(const Script *script) { | ||
287 | QByteArray a = QByteArray(); | ||
288 | QString str = script->script(); | ||
289 | a.setRawData(str.ascii(), str.length()); | ||
290 | emit sndBlock(a); | ||
291 | } | ||
292 | |||
293 | // Selection --------------------------------------------------------------- -- | 258 | // Selection --------------------------------------------------------------- -- |
294 | 259 | ||
295 | void EmulationLayer::onSelectionBegin(const int x, const int y) { | 260 | void EmulationLayer::onSelectionBegin(const int x, const int y) { |
296 | if (!connected) return; | 261 | if (!connected) return; |
297 | scr->setSelBeginXY(x,y); | 262 | scr->setSelBeginXY(x,y); |
298 | showBulk(); | 263 | showBulk(); |
299 | } | 264 | } |
300 | 265 | ||
301 | void EmulationLayer::onSelectionExtend(const int x, const int y) { | 266 | void EmulationLayer::onSelectionExtend(const int x, const int y) { |
302 | if (!connected) return; | 267 | if (!connected) return; |
303 | scr->setSelExtentXY(x,y); | 268 | scr->setSelExtentXY(x,y); |
304 | showBulk(); | 269 | showBulk(); |
305 | } | 270 | } |
306 | 271 | ||
307 | void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { | 272 | void EmulationLayer::setSelection(const BOOL preserve_line_breaks) { |
308 | if (!connected) return; | 273 | if (!connected) return; |
309 | QString t = scr->getSelText(preserve_line_breaks); | 274 | QString t = scr->getSelText(preserve_line_breaks); |
310 | if (!t.isNull()) gui->setSelection(t); | 275 | if (!t.isNull()) gui->setSelection(t); |
311 | } | 276 | } |
312 | 277 | ||
313 | void EmulationLayer::clearSelection() { | 278 | void EmulationLayer::clearSelection() { |
314 | if (!connected) return; | 279 | if (!connected) return; |
315 | scr->clearSelection(); | 280 | scr->clearSelection(); |
316 | showBulk(); | 281 | showBulk(); |
317 | } | 282 | } |
318 | 283 | ||
319 | // Refreshing -------------------------------------------------------------- -- | 284 | // Refreshing -------------------------------------------------------------- -- |
320 | 285 | ||
321 | #define BULK_TIMEOUT 20 | 286 | #define BULK_TIMEOUT 20 |
322 | 287 | ||
323 | /*! | 288 | /*! |
324 | called when \n comes in. Evtl. triggers showBulk at endBulk | 289 | called when \n comes in. Evtl. triggers showBulk at endBulk |
325 | */ | 290 | */ |
326 | 291 | ||
327 | void EmulationLayer::bulkNewline() | 292 | void EmulationLayer::bulkNewline() |
328 | { | 293 | { |
329 | bulk_nlcnt += 1; | 294 | bulk_nlcnt += 1; |
330 | bulk_incnt = 0; // reset bulk counter since `nl' rule applies | 295 | bulk_incnt = 0; // reset bulk counter since `nl' rule applies |
331 | } | 296 | } |
332 | 297 | ||
333 | /*! | 298 | /*! |
334 | */ | 299 | */ |
335 | 300 | ||
336 | void EmulationLayer::showBulk() | 301 | void EmulationLayer::showBulk() |
337 | { | 302 | { |
338 | bulk_nlcnt = 0; // reset bulk newline counter | 303 | bulk_nlcnt = 0; // reset bulk newline counter |
339 | bulk_incnt = 0; // reset bulk counter | 304 | bulk_incnt = 0; // reset bulk counter |
340 | if (connected) | 305 | if (connected) |
@@ -361,48 +326,49 @@ void EmulationLayer::bulkEnd() | |||
361 | else | 326 | else |
362 | bulk_timer.start(BULK_TIMEOUT,TRUE); | 327 | bulk_timer.start(BULK_TIMEOUT,TRUE); |
363 | } | 328 | } |
364 | 329 | ||
365 | void EmulationLayer::setConnect(bool c) | 330 | void EmulationLayer::setConnect(bool c) |
366 | { | 331 | { |
367 | connected = c; | 332 | connected = c; |
368 | if ( connected) | 333 | if ( connected) |
369 | { | 334 | { |
370 | onImageSizeChange(gui->lines(), gui->columns()); | 335 | onImageSizeChange(gui->lines(), gui->columns()); |
371 | showBulk(); | 336 | showBulk(); |
372 | } | 337 | } |
373 | else | 338 | else |
374 | { | 339 | { |
375 | scr->clearSelection(); | 340 | scr->clearSelection(); |
376 | } | 341 | } |
377 | } | 342 | } |
378 | 343 | ||
379 | // --------------------------------------------------------------------------- | 344 | // --------------------------------------------------------------------------- |
380 | 345 | ||
381 | /*! triggered by image size change of the Widget `gui'. | 346 | /*! triggered by image size change of the Widget `gui'. |
382 | 347 | ||
383 | This event is simply propagated to the attached screens | 348 | This event is simply propagated to the attached screens |
384 | and to the related serial line. | 349 | and to the related serial line. |
385 | */ | 350 | */ |
386 | 351 | ||
387 | void EmulationLayer::onImageSizeChange(int lines, int columns) | 352 | void EmulationLayer::onImageSizeChange(int lines, int columns) |
388 | { | 353 | { |
389 | if (!connected) return; | 354 | if (!connected) return; |
390 | screen[0]->resizeImage(lines,columns); | 355 | screen[0]->resizeImage(lines,columns); |
391 | screen[1]->resizeImage(lines,columns); | 356 | screen[1]->resizeImage(lines,columns); |
392 | showBulk(); | 357 | showBulk(); |
393 | emit ImageSizeChanged(lines,columns); // propagate event to serial line | 358 | emit ImageSizeChanged(lines,columns); // propagate event to serial line |
394 | } | 359 | } |
395 | 360 | ||
396 | void EmulationLayer::onHistoryCursorChange(int cursor) | 361 | void EmulationLayer::onHistoryCursorChange(int cursor) |
397 | { | 362 | { |
398 | if (!connected) return; | 363 | if (!connected) return; |
399 | scr->setHistCursor(cursor); | 364 | scr->setHistCursor(cursor); |
400 | showBulk(); | 365 | showBulk(); |
401 | } | 366 | } |
402 | 367 | ||
403 | void EmulationLayer::setColumns(int columns) | 368 | void EmulationLayer::setColumns(int columns) |
404 | { | 369 | { |
405 | //FIXME: this goes strange ways. | 370 | //FIXME: this goes strange ways. |
406 | // Can we put this straight or explain it at least? | 371 | // Can we put this straight or explain it at least? |
407 | emit changeColumns(columns); | 372 | emit changeColumns(columns); |
408 | } | 373 | } |
374 | |||
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 | |||
@@ -1,163 +1,145 @@ | |||
1 | /* -------------------------------------------------------------------------- */ | 1 | /* -------------------------------------------------------------------------- */ |
2 | /* */ | 2 | /* */ |
3 | /* [emulation.h] Fundamental Terminal Emulation */ | 3 | /* [emulation.h] Fundamental Terminal Emulation */ |
4 | /* */ | 4 | /* */ |
5 | /* -------------------------------------------------------------------------- */ | 5 | /* -------------------------------------------------------------------------- */ |
6 | /* */ | 6 | /* */ |
7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ | 7 | /* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */ |
8 | /* */ | 8 | /* */ |
9 | /* This file is part of Konsole - an X terminal for KDE */ | 9 | /* This file is part of Konsole - an X terminal for KDE */ |
10 | /* */ | 10 | /* */ |
11 | /* -------------------------------------------------------------------------- */ | 11 | /* -------------------------------------------------------------------------- */ |
12 | /* */ | 12 | /* */ |
13 | /* Ported Konsole to Qt/Embedded */ | 13 | /* Ported Konsole to Qt/Embedded */ |
14 | /* */ | 14 | /* */ |
15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ | 15 | /* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */ |
16 | /* */ | 16 | /* */ |
17 | /* -------------------------------------------------------------------------- */ | 17 | /* -------------------------------------------------------------------------- */ |
18 | /* -------------------------------------------------------------------------- */ | 18 | /* -------------------------------------------------------------------------- */ |
19 | /* */ | 19 | /* */ |
20 | /* made to a layer between io_layer and widget */ | 20 | /* made to a layer between io_layer and widget */ |
21 | /* */ | 21 | /* */ |
22 | /* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ | 22 | /* Copyright (C) 2002 by opie developers <opie@handhelds.org> */ |
23 | /* */ | 23 | /* */ |
24 | /* -------------------------------------------------------------------------- */ | 24 | /* -------------------------------------------------------------------------- */ |
25 | 25 | ||
26 | #ifndef EMULATION_LAYER_H | 26 | #ifndef EMULATION_LAYER_H |
27 | #define EMULATION_LAYER_H | 27 | #define EMULATION_LAYER_H |
28 | 28 | ||
29 | #include "widget_layer.h" | 29 | #include "widget_layer.h" |
30 | #include "screen.h" | 30 | #include "screen.h" |
31 | #include <qtimer.h> | 31 | #include <qtimer.h> |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | #include <qtextcodec.h> | 33 | #include <qtextcodec.h> |
34 | #include "keytrans.h" | 34 | #include "keytrans.h" |
35 | #include "script.h" | ||
36 | 35 | ||
37 | class EmulationLayer : public QObject | 36 | class EmulationLayer : public QObject |
38 | { Q_OBJECT | 37 | { Q_OBJECT |
39 | 38 | ||
40 | public: | 39 | public: |
41 | 40 | ||
42 | EmulationLayer( WidgetLayer* gui ); | 41 | EmulationLayer( WidgetLayer* gui ); |
43 | ~EmulationLayer(); | 42 | ~EmulationLayer(); |
44 | 43 | ||
45 | public: | 44 | public: |
46 | virtual void setHistory(bool on); | 45 | virtual void setHistory(bool on); |
47 | virtual bool history(); | 46 | virtual bool history(); |
48 | 47 | ||
49 | public slots: // signals incoming from Widget | 48 | public slots: // signals incoming from Widget |
50 | 49 | ||
51 | virtual void onImageSizeChange(int lines, int columns); | 50 | virtual void onImageSizeChange(int lines, int columns); |
52 | virtual void onHistoryCursorChange(int cursor); | 51 | virtual void onHistoryCursorChange(int cursor); |
53 | virtual void onKeyPress(QKeyEvent*); | 52 | virtual void onKeyPress(QKeyEvent*); |
54 | 53 | ||
55 | virtual void clearSelection(); | 54 | virtual void clearSelection(); |
56 | virtual void onSelectionBegin(const int x, const int y); | 55 | virtual void onSelectionBegin(const int x, const int y); |
57 | virtual void onSelectionExtend(const int x, const int y); | 56 | virtual void onSelectionExtend(const int x, const int y); |
58 | virtual void setSelection(const bool preserve_line_breaks); | 57 | virtual void setSelection(const bool preserve_line_breaks); |
59 | 58 | ||
60 | public slots: // signals incoming from data source | 59 | public slots: // signals incoming from data source |
61 | 60 | ||
62 | /** | 61 | /** |
63 | * to be called, when new data arrives | 62 | * to be called, when new data arrives |
64 | */ | 63 | */ |
65 | void onRcvBlock(const QByteArray&); | 64 | void onRcvBlock(const QByteArray&); |
66 | 65 | ||
67 | signals: | 66 | signals: |
68 | 67 | ||
69 | /** | 68 | /** |
70 | * will send data, encoded to suit emulation | 69 | * will send data, encoded to suit emulation |
71 | */ | 70 | */ |
72 | void sndBlock(const QByteArray&); | 71 | void sndBlock(const QByteArray&); |
73 | 72 | ||
74 | void ImageSizeChanged(int lines, int columns); | 73 | void ImageSizeChanged(int lines, int columns); |
75 | 74 | ||
76 | void changeColumns(int columns); | 75 | void changeColumns(int columns); |
77 | 76 | ||
78 | void changeTitle(int arg, const char* str); | 77 | void changeTitle(int arg, const char* str); |
79 | 78 | ||
80 | 79 | ||
81 | public: | 80 | public: |
82 | 81 | ||
83 | /** | 82 | /** |
84 | * process single char (decode) | 83 | * process single char (decode) |
85 | */ | 84 | */ |
86 | virtual void onRcvChar(int); | 85 | virtual void onRcvChar(int); |
87 | 86 | ||
88 | virtual void setMode (int) = 0; | 87 | virtual void setMode (int) = 0; |
89 | virtual void resetMode(int) = 0; | 88 | virtual void resetMode(int) = 0; |
90 | 89 | ||
91 | /** | 90 | /** |
92 | * @deprecated use qbytearray instead | 91 | * @deprecated use qbytearray instead |
93 | */ | 92 | */ |
94 | virtual void sendString(const char*) = 0; | 93 | virtual void sendString(const char*) = 0; |
95 | 94 | ||
96 | /** | 95 | /** |
97 | * sends a string to IOLayer | 96 | * sends a string to IOLayer |
98 | * encodes to suit emulation before | 97 | * encodes to suit emulation before |
99 | */ | 98 | */ |
100 | virtual void sendString(const QByteArray&) = 0; | 99 | virtual void sendString(const QByteArray&) = 0; |
101 | 100 | ||
102 | virtual void setConnect(bool r); | 101 | virtual void setConnect(bool r); |
103 | void setColumns(int columns); | 102 | void setColumns(int columns); |
104 | 103 | ||
105 | void setKeytrans(int no); | 104 | void setKeytrans(int no); |
106 | void setKeytrans(const char * no); | 105 | void setKeytrans(const char * no); |
107 | 106 | ||
108 | /* Scripts */ | ||
109 | |||
110 | /* Create a new script and record all typed characters */ | ||
111 | void startRecording(); | ||
112 | |||
113 | /* Return whether we are currently recording a script */ | ||
114 | bool isRecording(); | ||
115 | |||
116 | /* Return the current script (or NULL) */ | ||
117 | Script *script(); | ||
118 | |||
119 | /* Stop recording and remove the current script from memory */ | ||
120 | void clearScript(); | ||
121 | |||
122 | /* Run a script by forwarding its keys to the EmulationLayer */ | ||
123 | void runScript(const Script *); | ||
124 | protected: | 107 | protected: |
125 | 108 | ||
126 | WidgetLayer* gui; | 109 | WidgetLayer* gui; |
127 | Screen* scr; // referes to one `screen' | 110 | Screen* scr; // referes to one `screen' |
128 | Screen* screen[2]; // 0 = primary, 1 = alternate | 111 | Screen* screen[2]; // 0 = primary, 1 = alternate |
129 | void setScreen(int n); // set `scr' to `screen[n]' | 112 | void setScreen(int n); // set `scr' to `screen[n]' |
130 | 113 | ||
131 | bool connected; // communicate with widget | 114 | bool connected; // communicate with widget |
132 | 115 | ||
133 | void setCodec(int c); // codec number, 0 = locale, 1=utf8 | 116 | void setCodec(int c); // codec number, 0 = locale, 1=utf8 |
134 | 117 | ||
135 | QTextCodec* codec; | 118 | QTextCodec* codec; |
136 | QTextCodec* localeCodec; | 119 | QTextCodec* localeCodec; |
137 | QTextDecoder* decoder; | 120 | QTextDecoder* decoder; |
138 | 121 | ||
139 | KeyTrans* keytrans; | 122 | KeyTrans* keytrans; |
140 | 123 | ||
141 | // refreshing related material. | 124 | // refreshing related material. |
142 | // this is localized in the class. | 125 | // this is localized in the class. |
143 | private slots: // triggered by timer | 126 | private slots: // triggered by timer |
144 | 127 | ||
145 | void showBulk(); | 128 | void showBulk(); |
146 | 129 | ||
147 | private: | 130 | private: |
148 | 131 | ||
149 | void bulkNewline(); | 132 | void bulkNewline(); |
150 | void bulkStart(); | 133 | void bulkStart(); |
151 | void bulkEnd(); | 134 | void bulkEnd(); |
152 | 135 | ||
153 | private: | 136 | private: |
154 | 137 | ||
155 | QTimer bulk_timer; | 138 | QTimer bulk_timer; |
156 | int bulk_nlcnt; // bulk newline counter | 139 | int bulk_nlcnt; // bulk newline counter |
157 | char* SelectedText; | 140 | char* SelectedText; |
158 | int bulk_incnt; // bulk counter | 141 | int bulk_incnt; // bulk counter |
159 | Script *m_script; | ||
160 | 142 | ||
161 | }; | 143 | }; |
162 | 144 | ||
163 | #endif // ifndef EMULATION_H | 145 | #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 | |||
@@ -241,131 +241,127 @@ void MainWindow::initUI() { | |||
241 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), | 241 | connect(m_consoleWindow, SIGNAL(activated(Session*) ), |
242 | this, SLOT(slotSessionChanged(Session*) ) ); | 242 | this, SLOT(slotSessionChanged(Session*) ) ); |
243 | setCentralWidget( m_consoleWindow ); | 243 | setCentralWidget( m_consoleWindow ); |
244 | 244 | ||
245 | } | 245 | } |
246 | 246 | ||
247 | ProfileManager* MainWindow::manager() { | 247 | ProfileManager* MainWindow::manager() { |
248 | return m_manager; | 248 | return m_manager; |
249 | } | 249 | } |
250 | TabWidget* MainWindow::tabWidget() { | 250 | TabWidget* MainWindow::tabWidget() { |
251 | return m_consoleWindow; | 251 | return m_consoleWindow; |
252 | } | 252 | } |
253 | void MainWindow::populateProfiles() { | 253 | void MainWindow::populateProfiles() { |
254 | m_sessionsPop->clear(); | 254 | m_sessionsPop->clear(); |
255 | Profile::ValueList list = manager()->all(); | 255 | Profile::ValueList list = manager()->all(); |
256 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { | 256 | for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) { |
257 | m_sessionsPop->insertItem( (*it).name() ); | 257 | m_sessionsPop->insertItem( (*it).name() ); |
258 | } | 258 | } |
259 | 259 | ||
260 | } | 260 | } |
261 | MainWindow::~MainWindow() { | 261 | MainWindow::~MainWindow() { |
262 | delete m_factory; | 262 | delete m_factory; |
263 | manager()->save(); | 263 | manager()->save(); |
264 | } | 264 | } |
265 | 265 | ||
266 | MetaFactory* MainWindow::factory() { | 266 | MetaFactory* MainWindow::factory() { |
267 | return m_factory; | 267 | return m_factory; |
268 | } | 268 | } |
269 | 269 | ||
270 | Session* MainWindow::currentSession() { | 270 | Session* MainWindow::currentSession() { |
271 | return m_curSession; | 271 | return m_curSession; |
272 | } | 272 | } |
273 | 273 | ||
274 | QList<Session> MainWindow::sessions() { | 274 | QList<Session> MainWindow::sessions() { |
275 | return m_sessions; | 275 | return m_sessions; |
276 | } | 276 | } |
277 | 277 | ||
278 | void MainWindow::slotNew() { | 278 | void MainWindow::slotNew() { |
279 | ProfileEditorDialog dlg(factory() ); | 279 | ProfileEditorDialog dlg(factory() ); |
280 | dlg.showMaximized(); | 280 | dlg.showMaximized(); |
281 | int ret = dlg.exec(); | 281 | int ret = dlg.exec(); |
282 | 282 | ||
283 | if ( ret == QDialog::Accepted ) { | 283 | if ( ret == QDialog::Accepted ) { |
284 | create( dlg.profile() ); | 284 | create( dlg.profile() ); |
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | void MainWindow::slotRecordScript() { | 288 | void MainWindow::slotRecordScript() { |
289 | /* if (currentSession()) { | 289 | if (currentSession()) { |
290 | currentSession()->emulationLayer()->startRecording(); | 290 | currentSession()->emulationHandler()->startRecording(); |
291 | } | 291 | } |
292 | */ | ||
293 | } | 292 | } |
294 | 293 | ||
295 | void MainWindow::slotSaveScript() { | 294 | void MainWindow::slotSaveScript() { |
296 | /* if (currentSession() && currentSession()->emulationLayer()->isRecording()) { | 295 | if (currentSession() && currentSession()->emulationHandler()->isRecording()) { |
297 | MimeTypes types; | 296 | MimeTypes types; |
298 | QStringList script; | 297 | QStringList script; |
299 | script << "text/plain"; | 298 | script << "text/plain"; |
300 | types.insert("Script", script); | 299 | types.insert("Script", script); |
301 | QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); | 300 | QString filename = OFileDialog::getSaveFileName(2, "/", QString::null, types); |
302 | if (!filename.isEmpty()) { | 301 | if (!filename.isEmpty()) { |
303 | currentSession()->emulationLayer()->script()->saveTo(filename); | 302 | currentSession()->emulationHandler()->script()->saveTo(filename); |
304 | currentSession()->emulationLayer()->clearScript(); | 303 | currentSession()->emulationHandler()->clearScript(); |
305 | } | 304 | } |
306 | } | 305 | } |
307 | */ | ||
308 | } | 306 | } |
309 | 307 | ||
310 | void MainWindow::slotRunScript() { | 308 | void MainWindow::slotRunScript() { |
311 | /* | ||
312 | if (currentSession()) { | 309 | if (currentSession()) { |
313 | MimeTypes types; | 310 | MimeTypes types; |
314 | QStringList script; | 311 | QStringList script; |
315 | script << "text/plain"; | 312 | script << "text/plain"; |
316 | types.insert("Script", script); | 313 | types.insert("Script", script); |
317 | QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); | 314 | QString filename = OFileDialog::getOpenFileName(2, "/", QString::null, types); |
318 | if (!filename.isEmpty()) { | 315 | if (!filename.isEmpty()) { |
319 | Script script(DocLnk(filename).file()); | 316 | Script script(DocLnk(filename).file()); |
320 | currentSession()->emulationLayer()->runScript(&script); | 317 | currentSession()->emulationHandler()->runScript(&script); |
321 | } | 318 | } |
322 | } | 319 | } |
323 | */ | ||
324 | } | 320 | } |
325 | 321 | ||
326 | void MainWindow::slotConnect() { | 322 | void MainWindow::slotConnect() { |
327 | if ( currentSession() ) { | 323 | if ( currentSession() ) { |
328 | bool ret = currentSession()->layer()->open(); | 324 | bool ret = currentSession()->layer()->open(); |
329 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), | 325 | if(!ret) QMessageBox::warning(currentSession()->widgetStack(), |
330 | QObject::tr("Failed"), | 326 | QObject::tr("Failed"), |
331 | QObject::tr("Connecting failed for this session.")); | 327 | QObject::tr("Connecting failed for this session.")); |
332 | else { | 328 | else { |
333 | m_connect->setEnabled( false ); | 329 | m_connect->setEnabled( false ); |
334 | m_disconnect->setEnabled( true ); | 330 | m_disconnect->setEnabled( true ); |
335 | } | 331 | } |
336 | } | 332 | } |
337 | } | 333 | } |
338 | 334 | ||
339 | void MainWindow::slotDisconnect() { | 335 | void MainWindow::slotDisconnect() { |
340 | if ( currentSession() ) { | 336 | if ( currentSession() ) { |
341 | currentSession()->layer()->close(); | 337 | currentSession()->layer()->close(); |
342 | m_connect->setEnabled( true ); | 338 | m_connect->setEnabled( true ); |
343 | m_disconnect->setEnabled( false ); | 339 | m_disconnect->setEnabled( false ); |
344 | } | 340 | } |
345 | } | 341 | } |
346 | 342 | ||
347 | void MainWindow::slotTerminate() { | 343 | void MainWindow::slotTerminate() { |
348 | if ( currentSession() ) | 344 | if ( currentSession() ) |
349 | currentSession()->layer()->close(); | 345 | currentSession()->layer()->close(); |
350 | 346 | ||
351 | slotClose(); | 347 | slotClose(); |
352 | /* FIXME move to the next session */ | 348 | /* FIXME move to the next session */ |
353 | } | 349 | } |
354 | 350 | ||
355 | void MainWindow::slotConfigure() { | 351 | void MainWindow::slotConfigure() { |
356 | ConfigDialog conf( manager()->all(), factory() ); | 352 | ConfigDialog conf( manager()->all(), factory() ); |
357 | conf.showMaximized(); | 353 | conf.showMaximized(); |
358 | 354 | ||
359 | int ret = conf.exec(); | 355 | int ret = conf.exec(); |
360 | 356 | ||
361 | if ( QDialog::Accepted == ret ) { | 357 | if ( QDialog::Accepted == ret ) { |
362 | manager()->setProfiles( conf.list() ); | 358 | manager()->setProfiles( conf.list() ); |
363 | manager()->save(); | 359 | manager()->save(); |
364 | populateProfiles(); | 360 | populateProfiles(); |
365 | } | 361 | } |
366 | } | 362 | } |
367 | /* | 363 | /* |
368 | * we will remove | 364 | * we will remove |
369 | * this window from the tabwidget | 365 | * this window from the tabwidget |
370 | * remove it from the list | 366 | * remove it from the list |
371 | * delete it | 367 | * delete it |
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 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include "script.h" | 3 | #include "script.h" |
4 | 4 | ||
5 | Script::Script() { | 5 | Script::Script() { |
6 | } | 6 | } |
7 | 7 | ||
8 | Script::Script(const QString fileName) { | 8 | Script::Script(const QString fileName) { |
9 | QFile file(fileName); | 9 | QFile file(fileName); |
10 | QTextStream stream(&file); | 10 | m_script = file.readAll(); |
11 | while (!stream.atEnd()) { | ||
12 | appendString(stream.readLine()); | ||
13 | } | ||
14 | } | 11 | } |
15 | 12 | ||
16 | void Script::saveTo(const QString fileName) const { | 13 | void Script::saveTo(const QString fileName) const { |
17 | QFile file(fileName); | 14 | QFile file(fileName); |
18 | file.open(IO_WriteOnly); | 15 | file.open(IO_WriteOnly); |
19 | file.writeBlock(m_script.ascii(), m_script.length()); | 16 | file.writeBlock(m_script); |
20 | file.close(); | 17 | file.close(); |
21 | } | 18 | } |
22 | 19 | ||
23 | 20 | ||
24 | void Script::appendString(const QString string) { | 21 | void Script::append(const QByteArray &data) { |
25 | m_script += string; | 22 | int size = m_script.size(); |
23 | m_script.resize(size + data.size()); | ||
24 | memcpy(m_script.data() + size, data.data(), data.size()); | ||
26 | } | 25 | } |
27 | 26 | ||
28 | QString Script::script() const { | 27 | QByteArray Script::script() const { |
29 | return m_script; | 28 | return m_script; |
30 | } | 29 | } |
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 @@ | |||
1 | #ifndef CONSOLE_SCRIPT_H | 1 | #ifndef CONSOLE_SCRIPT_H |
2 | #define CONSOLE_SCRIPT_H | 2 | #define CONSOLE_SCRIPT_H |
3 | 3 | ||
4 | #include <qstring.h> | 4 | #include <qstring.h> |
5 | 5 | ||
6 | /* Very simple scripting - this class stores keys received | 6 | /* Very simple scripting - this class stores keys received |
7 | * by emulation_layer */ | 7 | * by emulation_layer */ |
8 | 8 | ||
9 | class Script { | 9 | class Script { |
10 | public: | 10 | public: |
11 | /* Construct an empty script */ | 11 | /* Construct an empty script */ |
12 | Script(); | 12 | Script(); |
13 | 13 | ||
14 | /* Load a script from a text file */ | 14 | /* Load a script from a text file */ |
15 | Script(const QString fileName); | 15 | Script(const QString fileName); |
16 | 16 | ||
17 | /* Append a line to the script */ | 17 | /* Append a line to the script */ |
18 | void appendString(const QString string); | 18 | void append(const QByteArray &data); |
19 | 19 | ||
20 | /* Save this script to a file */ | 20 | /* Save this script to a file */ |
21 | void saveTo(const QString fileName) const; | 21 | void saveTo(const QString fileName) const; |
22 | 22 | ||
23 | /* Return the script's content */ | 23 | /* Return the script's content */ |
24 | QString script() const; | 24 | QByteArray script() const; |
25 | protected: | 25 | protected: |
26 | QString m_script; | 26 | QByteArray m_script; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | 29 | ||
30 | #endif /* CONSOLE_SCRIPT_H */ | 30 | #endif /* CONSOLE_SCRIPT_H */ |