Diffstat (limited to 'noncore/apps/opie-console/emulation_layer.cpp') (more/less context) (ignore 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 | |||
@@ -98,24 +98,25 @@ | |||
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; | ||
110 | 111 | ||
111 | QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); | 112 | QObject::connect(&bulk_timer, SIGNAL( timeout() ), this, SLOT( showBulk() ) ); |
112 | QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), | 113 | QObject::connect(gui,SIGNAL( imageSizeChanged( int, int ) ), |
113 | this,SLOT( onImageSizeChange( int, int ) ) ); | 114 | this,SLOT( onImageSizeChange( int, int ) ) ); |
114 | QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), | 115 | QObject::connect(gui,SIGNAL( changedHistoryCursor( int ) ), |
115 | this,SLOT( historyCursorChange( int ) ) ); | 116 | this,SLOT( historyCursorChange( int ) ) ); |
116 | QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), | 117 | QObject::connect(gui,SIGNAL( keyPressed( QKeyEvent* ) ), |
117 | this,SLOT( onKeyPress( QKeyEvent* ) ) ); | 118 | this,SLOT( onKeyPress( QKeyEvent* ) ) ); |
118 | QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), | 119 | QObject::connect(gui,SIGNAL( selectionBegin( const int, const int) ), |
119 | this,SLOT( onSelectionBegin( const int, const int ) ) ); | 120 | this,SLOT( onSelectionBegin( const int, const int ) ) ); |
120 | QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), | 121 | QObject::connect(gui,SIGNAL( selectionExtended( const int, const int ) ), |
121 | this,SLOT( onSelectionExtend( const int,const int ) ) ); | 122 | this,SLOT( onSelectionExtend( const int,const int ) ) ); |
@@ -123,24 +124,26 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui ) | |||
123 | this,SLOT( setSelection( const bool ) ) ); | 124 | this,SLOT( setSelection( const bool ) ) ); |
124 | QObject::connect(gui,SIGNAL( selectionCleared() ), | 125 | QObject::connect(gui,SIGNAL( selectionCleared() ), |
125 | this,SLOT( clearSelection() ) ); | 126 | this,SLOT( clearSelection() ) ); |
126 | } | 127 | } |
127 | 128 | ||
128 | /*! | 129 | /*! |
129 | */ | 130 | */ |
130 | 131 | ||
131 | EmulationLayer::~EmulationLayer() | 132 | EmulationLayer::~EmulationLayer() |
132 | { | 133 | { |
133 | delete screen[0]; | 134 | delete screen[0]; |
134 | delete screen[1]; | 135 | delete screen[1]; |
136 | if (isRecording()) | ||
137 | clearScript(); | ||
135 | bulk_timer.stop(); | 138 | bulk_timer.stop(); |
136 | } | 139 | } |
137 | 140 | ||
138 | /*! change between primary and alternate screen | 141 | /*! change between primary and alternate screen |
139 | */ | 142 | */ |
140 | 143 | ||
141 | void EmulationLayer::setScreen(int n) | 144 | void EmulationLayer::setScreen(int n) |
142 | { | 145 | { |
143 | scr = screen[n&1]; | 146 | scr = screen[n&1]; |
144 | } | 147 | } |
145 | 148 | ||
146 | void EmulationLayer::setHistory(bool on) | 149 | void EmulationLayer::setHistory(bool on) |
@@ -219,24 +222,28 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev ) | |||
219 | if (!ev->text().isEmpty()) | 222 | if (!ev->text().isEmpty()) |
220 | { // A block of text | 223 | { // A block of text |
221 | // Note that the text is proper unicode. | 224 | // Note that the text is proper unicode. |
222 | // We should do a conversion here, but since this | 225 | // We should do a conversion here, but since this |
223 | // routine will never be used, we simply emit plain ascii. | 226 | // routine will never be used, we simply emit plain ascii. |
224 | sendString( ev->text().ascii() ); //,ev->text().length()); | 227 | sendString( ev->text().ascii() ); //,ev->text().length()); |
225 | } | 228 | } |
226 | else if (ev->ascii()>0) | 229 | else if (ev->ascii()>0) |
227 | { | 230 | { |
228 | QByteArray c = QByteArray( 1 ); | 231 | QByteArray c = QByteArray( 1 ); |
229 | c.at( 0 ) = ev->ascii(); | 232 | c.at( 0 ) = ev->ascii(); |
230 | // ibot: qbytearray is emited not char* | 233 | // ibot: qbytearray is emited not char* |
234 | |||
235 | /* Are we currently recording a script? If so, store the typed character */ | ||
236 | if (isRecording()) | ||
237 | m_script->appendString(ev->text()); | ||
231 | emit sndBlock( (QByteArray) c ); | 238 | emit sndBlock( (QByteArray) c ); |
232 | } | 239 | } |
233 | } | 240 | } |
234 | 241 | ||
235 | // Unblocking, Byte to Unicode translation --------------------------------- -- | 242 | // Unblocking, Byte to Unicode translation --------------------------------- -- |
236 | 243 | ||
237 | /* | 244 | /* |
238 | We are doing code conversion from locale to unicode first. | 245 | We are doing code conversion from locale to unicode first. |
239 | */ | 246 | */ |
240 | 247 | ||
241 | void EmulationLayer::onRcvBlock(const QByteArray &s ) | 248 | void EmulationLayer::onRcvBlock(const QByteArray &s ) |
242 | { | 249 | { |
@@ -245,24 +252,53 @@ void EmulationLayer::onRcvBlock(const QByteArray &s ) | |||
245 | for (int i = 0; i < s.size(); i++) | 252 | for (int i = 0; i < s.size(); i++) |
246 | { | 253 | { |
247 | //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? | 254 | //TODO: ibot: maybe decoding qbytearray to unicode in io_layer? |
248 | QString result = decoder->toUnicode(&s[i],1); | 255 | QString result = decoder->toUnicode(&s[i],1); |
249 | int reslen = result.length(); | 256 | int reslen = result.length(); |
250 | for (int j = 0; j < reslen; j++) | 257 | for (int j = 0; j < reslen; j++) |
251 | onRcvChar(result[j].unicode()); | 258 | onRcvChar(result[j].unicode()); |
252 | if (s[i] == '\n') bulkNewline(); | 259 | if (s[i] == '\n') bulkNewline(); |
253 | } | 260 | } |
254 | bulkEnd(); | 261 | bulkEnd(); |
255 | } | 262 | } |
256 | 263 | ||
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 | |||
257 | // Selection --------------------------------------------------------------- -- | 293 | // Selection --------------------------------------------------------------- -- |
258 | 294 | ||
259 | void EmulationLayer::onSelectionBegin(const int x, const int y) { | 295 | void EmulationLayer::onSelectionBegin(const int x, const int y) { |
260 | if (!connected) return; | 296 | if (!connected) return; |
261 | scr->setSelBeginXY(x,y); | 297 | scr->setSelBeginXY(x,y); |
262 | showBulk(); | 298 | showBulk(); |
263 | } | 299 | } |
264 | 300 | ||
265 | void EmulationLayer::onSelectionExtend(const int x, const int y) { | 301 | void EmulationLayer::onSelectionExtend(const int x, const int y) { |
266 | if (!connected) return; | 302 | if (!connected) return; |
267 | scr->setSelExtentXY(x,y); | 303 | scr->setSelExtentXY(x,y); |
268 | showBulk(); | 304 | showBulk(); |