summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/emulation_handler.cpp34
-rw-r--r--noncore/apps/opie-console/emulation_handler.h19
-rw-r--r--noncore/apps/opie-console/emulation_layer.cpp36
-rw-r--r--noncore/apps/opie-console/emulation_layer.h18
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp16
-rw-r--r--noncore/apps/opie-console/script.cpp15
-rw-r--r--noncore/apps/opie-console/script.h6
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,147 +1,179 @@
#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();
}
QFont EmulationHandler::font( int id ) {
QString name;
int size = 0;
switch(id ) {
default: // fall through
case 0:
name = QString::fromLatin1("Micro");
size = 4;
break;
case 1:
name = QString::fromLatin1("Fixed");
size = 7;
break;
case 2:
name = QString::fromLatin1("Fixed");
size = 12;
break;
}
QFont font(name, size, QFont::Normal );
font.setFixedPitch(TRUE );
return font;
}
QColor EmulationHandler::foreColor(int col) {
QColor co;
/* we need to switch it */
switch( col ) {
default:
case Profile::White:
/* color is black */
co = Qt::white;
break;
case Profile::Black:
co = Qt::black;
break;
case Profile::Green:
qWarning("Foreground green");
co = Qt::green;
break;
case Profile::Orange:
qWarning("Foreground orange");
// FIXME needs better color here
co = Qt::darkYellow;
break;
}
return co;
}
QColor EmulationHandler::backColor(int col ) {
QColor co;
/* we need to switch it */
switch( 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
@@ -1,73 +1,90 @@
#ifndef OPIE_EMULATION_HANDLER_H
#define OPIE_EMULATION_HANDLER_H
#include <qobject.h>
#include <qcolor.h>
#include <qcstring.h>
/*
* 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
@@ -14,395 +14,361 @@
/* */
/* Copyright (C) 2000 by John Ryland <jryland@trolltech.com> */
/* */
/* -------------------------------------------------------------------------- */
/* */
/* Modified to suit opie-console */
/* */
/* Copyright (C) 2002 by opie developers <opie@handhelds.org> */
/* */
/* -------------------------------------------------------------------------- */
/*! \class EmulationLayer
\brief Mediator between Widget and Screen.
This class is responsible to scan the escapes sequences of the terminal
emulation and to map it to their corresponding semantic complements.
Thus this module knows mainly about decoding escapes sequences and
is a stateless device w.r.t. the semantics.
It is also responsible to refresh the Widget by certain rules.
\sa Widget \sa Screen
\par A note on refreshing
Although the modifications to the current screen image could immediately
be propagated via `Widget' to the graphical surface, we have chosen
another way here.
The reason for doing so is twofold.
First, experiments show that directly displaying the operation results
in slowing down the overall performance of emulations. Displaying
individual characters using X11 creates a lot of overhead.
Second, by using the following refreshing method, the screen operations
can be completely separated from the displaying. This greatly simplifies
the programmer's task of coding and maintaining the screen operations,
since one need not worry about differential modifications on the
display affecting the operation of concern.
We use a refreshing algorithm here that has been adoped from rxvt/kvt.
By this, refreshing is driven by a timer, which is (re)started whenever
a new bunch of data to be interpreted by the emulation arives at `onRcvBlock'.
As soon as no more data arrive for `BULK_TIMEOUT' milliseconds, we trigger
refresh. This rule suits both bulk display operation as done by curses as
well as individual characters typed.
(BULK_TIMEOUT < 1000 / max characters received from keyboard per second).
Additionally, we trigger refreshing by newlines comming in to make visual
snapshots of lists as produced by `cat', `ls' and likely programs, thereby
producing the illusion of a permanent and immediate display operation.
As a sort of catch-all needed for cases where none of the above
conditions catch, the screen refresh is also triggered by a count
of incoming bulks (`bulk_incnt').
*/
/* FIXME
- evtl. the bulk operations could be made more transparent.
*/
#include "emulation_layer.h"
#include "widget_layer.h"
#include "screen.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <qkeycode.h>
/* ------------------------------------------------------------------------- */
/* */
/* 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)
{
//FIXME: check whether we have to free codec
codec = c ? QTextCodec::codecForName("utf8")
: QTextCodec::codecForLocale();
if (decoder) delete decoder;
decoder = codec->makeDecoder();
}
void EmulationLayer::setKeytrans(int no)
{
keytrans = KeyTrans::find(no);
}
void EmulationLayer::setKeytrans(const char * no)
{
keytrans = KeyTrans::find(no);
}
// Interpreting Codes ---------------------------------------------------------
/*
This section deals with decoding the incoming character stream.
Decoding means here, that the stream is first seperated into `tokens'
which are then mapped to a `meaning' provided as operations by the
`Screen' class.
*/
/*!
*/
void EmulationLayer::onRcvChar(int c)
// process application unicode input to terminal
// this is a trivial scanner
{
c &= 0xff;
switch (c)
{
case '\b' : scr->BackSpace(); break;
case '\t' : scr->Tabulate(); break;
case '\n' : scr->NewLine(); break;
case '\r' : scr->Return(); break;
case 0x07 : gui->bell(); break;
default : scr->ShowCharacter(c); break;
};
}
/* ------------------------------------------------------------------------- */
/* */
/* 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();
}
// Refreshing -------------------------------------------------------------- --
#define BULK_TIMEOUT 20
/*!
called when \n comes in. Evtl. triggers showBulk at endBulk
*/
void EmulationLayer::bulkNewline()
{
bulk_nlcnt += 1;
bulk_incnt = 0; // reset bulk counter since `nl' rule applies
}
/*!
*/
void EmulationLayer::showBulk()
{
bulk_nlcnt = 0; // reset bulk newline counter
bulk_incnt = 0; // reset bulk counter
if (connected)
{
QArray<Character> image = scr->getCookedImage(); // get the image
gui->setImage(image,
scr->getLines(),
scr->getColumns()); // actual refresh
delete image;
//FIXME: check that we do not trigger other draw event here.
gui->setScroll(scr->getHistCursor(),scr->getHistLines());
}
}
void EmulationLayer::bulkStart()
{
if (bulk_timer.isActive()) bulk_timer.stop();
}
void EmulationLayer::bulkEnd()
{
if ( bulk_nlcnt > gui->lines() || bulk_incnt > 20 )
showBulk(); // resets bulk_??cnt to 0, too.
else
bulk_timer.start(BULK_TIMEOUT,TRUE);
}
void EmulationLayer::setConnect(bool c)
{
connected = c;
if ( connected)
{
onImageSizeChange(gui->lines(), gui->columns());
showBulk();
}
else
{
scr->clearSelection();
}
}
// ---------------------------------------------------------------------------
/*! triggered by image size change of the Widget `gui'.
This event is simply propagated to the attached screens
and to the related serial line.
*/
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
@@ -1,163 +1,145 @@
/* -------------------------------------------------------------------------- */
/* */
/* [emulation.h] Fundamental Terminal Emulation */
/* */
/* -------------------------------------------------------------------------- */
/* */
/* Copyright (c) 1997,1998 by Lars Doelle <lars.doelle@on-line.de> */
/* */
/* This file is part of Konsole - an X terminal for KDE */
/* */
/* -------------------------------------------------------------------------- */
/* */
/* 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);
public slots: // signals incoming from data source
/**
* to be called, when new data arrives
*/
void onRcvBlock(const QByteArray&);
signals:
/**
* will send data, encoded to suit emulation
*/
void sndBlock(const QByteArray&);
void ImageSizeChanged(int lines, int columns);
void changeColumns(int columns);
void changeTitle(int arg, const char* str);
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
@@ -193,227 +193,223 @@ void MainWindow::initUI() {
-1, 0);
/* insert the connection menu */
m_bar->insertItem( tr("Connection"), m_console );
/* the scripts menu */
m_bar->insertItem( tr("Scripts"), m_scripts );
/* the settings menu */
// m_bar->insertItem( tr("Settings"), m_settings );
/* and the keyboard */
m_keyBar = new QToolBar(this);
addToolBar( m_keyBar, "Keyboard", QMainWindow::Top, TRUE );
m_keyBar->setHorizontalStretchable( TRUE );
m_keyBar->hide();
m_kb = new FunctionKeyboard(m_keyBar);
connect(m_kb, SIGNAL(keyPressed(ushort, ushort, bool, bool, bool)),
this, SLOT(slotKeyReceived(ushort, ushort, bool, bool, bool)));
m_buttonBar = new QToolBar( this );
addToolBar( m_buttonBar, "Buttons", QMainWindow::Top, TRUE );
m_buttonBar->setHorizontalStretchable( TRUE );
m_buttonBar->hide();
m_qb = new QuickButton( m_buttonBar );
connect( m_qb, SIGNAL( keyPressed( ushort, ushort, bool, bool, bool) ),
this, SLOT( slotKeyReceived( ushort, ushort, bool, bool, bool) ) );
m_connect->setEnabled( false );
m_disconnect->setEnabled( false );
m_terminate->setEnabled( false );
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false );
m_saveScript->setEnabled( false );
m_runScript->setEnabled( false );
m_fullscreen->setEnabled( false );
m_closewindow->setEnabled( false );
/*
* connect to the menu activation
*/
connect( m_sessionsPop, SIGNAL(activated( int ) ),
this, SLOT(slotProfile( int ) ) );
m_consoleWindow = new TabWidget( this, "blah");
connect(m_consoleWindow, SIGNAL(activated(Session*) ),
this, SLOT(slotSessionChanged(Session*) ) );
setCentralWidget( m_consoleWindow );
}
ProfileManager* MainWindow::manager() {
return m_manager;
}
TabWidget* MainWindow::tabWidget() {
return m_consoleWindow;
}
void MainWindow::populateProfiles() {
m_sessionsPop->clear();
Profile::ValueList list = manager()->all();
for (Profile::ValueList::Iterator it = list.begin(); it != list.end(); ++it ) {
m_sessionsPop->insertItem( (*it).name() );
}
}
MainWindow::~MainWindow() {
delete m_factory;
manager()->save();
}
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() {
if ( currentSession() )
currentSession()->layer()->close();
slotClose();
/* FIXME move to the next session */
}
void MainWindow::slotConfigure() {
ConfigDialog conf( manager()->all(), factory() );
conf.showMaximized();
int ret = conf.exec();
if ( QDialog::Accepted == ret ) {
manager()->setProfiles( conf.list() );
manager()->save();
populateProfiles();
}
}
/*
* we will remove
* this window from the tabwidget
* remove it from the list
* delete it
* and set the currentSession()
*/
void MainWindow::slotClose() {
if (!currentSession() )
return;
Session* ses = currentSession();
qWarning("removing! currentSession %s", currentSession()->name().latin1() );
/* set to NULL to be safe, if its needed slotSessionChanged resets it automatically */
m_curSession = NULL;
tabWidget()->remove( /*currentSession()*/ses );
/*it's autodelete */
m_sessions.remove( ses );
qWarning("after remove!!");
if (!currentSession() ) {
m_connect->setEnabled( false );
m_disconnect->setEnabled( false );
m_terminate->setEnabled( false );
m_transfer->setEnabled( false );
m_recordScript->setEnabled( false );
m_saveScript->setEnabled( false );
m_runScript->setEnabled( false );
m_fullscreen->setEnabled( false );
m_closewindow->setEnabled( false );
}
}
/*
* We will get the name
* Then the profile
* and then we will make a profile
*/
void MainWindow::slotProfile( int id) {
Profile prof = manager()->profile( m_sessionsPop->text( id) );
create( prof );
}
void MainWindow::create( const Profile& prof ) {
Session *ses = manager()->fromProfile( prof, tabWidget() );
if((!ses) || (!ses->layer()) || (!ses->widgetStack()))
{
QMessageBox::warning(this,
QObject::tr("Session failed"),
QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
//if(ses) delete ses;
return;
}
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 */