summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/emulation_layer.cpp36
-rw-r--r--noncore/apps/opie-console/emulation_layer.h19
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp56
-rw-r--r--noncore/apps/opie-console/mainwindow.h8
-rw-r--r--noncore/apps/opie-console/opie-console.pro4
-rw-r--r--noncore/apps/opie-console/script.cpp30
-rw-r--r--noncore/apps/opie-console/script.h30
7 files changed, 178 insertions, 5 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 @@
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 ) ) );
@@ -123,24 +124,26 @@ EmulationLayer::EmulationLayer( WidgetLayer* gui )
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)
@@ -219,24 +222,28 @@ void EmulationLayer::onKeyPress( QKeyEvent* ev )
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 )
{
@@ -245,24 +252,53 @@ void EmulationLayer::onRcvBlock(const QByteArray &s )
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();
diff --git a/noncore/apps/opie-console/emulation_layer.h b/noncore/apps/opie-console/emulation_layer.h
index 91a4856..928ad04 100644
--- a/noncore/apps/opie-console/emulation_layer.h
+++ b/noncore/apps/opie-console/emulation_layer.h
@@ -23,24 +23,25 @@
/* */
/* -------------------------------------------------------------------------- */
#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();
@@ -95,24 +96,40 @@ public:
/**
* 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;
@@ -130,17 +147,17 @@ private slots: // triggered by timer
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 8f5d56b..46c5bed 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -1,52 +1,54 @@
#include <qaction.h>
#include <qmenubar.h>
#include <qlabel.h>
#include <qpopupmenu.h>
#include <qtoolbar.h>
#include <qpe/resource.h>
-
+#include <opie/ofiledialog.h>
#include "profileeditordialog.h"
#include "configdialog.h"
#include "default.h"
#include "metafactory.h"
#include "profile.h"
#include "profilemanager.h"
#include "mainwindow.h"
#include "tabwidget.h"
#include "transferdialog.h"
#include "function_keyboard.h"
+#include "script.h"
MainWindow::MainWindow() {
m_factory = new MetaFactory();
Default def(m_factory);
m_sessions.setAutoDelete( TRUE );
m_curSession = 0;
m_manager = new ProfileManager( m_factory );
m_manager->load();
initUI();
populateProfiles();
}
void MainWindow::initUI() {
setToolBarsMovable( FALSE );
/* tool bar for the menu */
m_tool = new QToolBar( this );
m_tool->setHorizontalStretchable( TRUE );
m_bar = new QMenuBar( m_tool );
m_console = new QPopupMenu( this );
+ m_scripts = new QPopupMenu( this );
m_sessionsPop= new QPopupMenu( this );
m_settings = new QPopupMenu( this );
/* add a toolbar for icons */
m_icons = new QToolBar(this);
/*
* new Action for new sessions
*/
QAction* a = new QAction(tr("New Connection"),
Resource::loadPixmap( "new" ),
QString::null, 0, this, 0);
@@ -97,44 +99,62 @@ void MainWindow::initUI() {
/*
* the settings action
*/
m_setProfiles = new QAction(tr("Configure Profiles"),
Resource::loadPixmap( "SettingsIcon" ),
QString::null, 0, this, 0);
m_setProfiles->addTo( m_settings );
m_setProfiles->addTo( m_icons );
connect( m_setProfiles, SIGNAL(activated() ),
this, SLOT(slotConfigure() ) );
/*
+ * script actions
+ */
+ m_recordScript = new QAction(tr("Record Script"), QString::null, 0, this, 0);
+ m_recordScript->addTo(m_scripts);
+ connect(m_recordScript, SIGNAL(activated()), this, SLOT(slotRecordScript()));
+
+ m_saveScript = new QAction(tr("Save Script"), QString::null, 0, this, 0);
+ m_saveScript->addTo(m_scripts);
+ connect(m_saveScript, SIGNAL(activated()), this, SLOT(slotSaveScript()));
+
+ m_runScript = new QAction(tr("Run Script"), QString::null, 0, this, 0);
+ m_runScript->addTo(m_scripts);
+ connect(m_runScript, SIGNAL(activated()), this, SLOT(slotRunScript()));
+
+ /*
* action that open/closes the keyboard
*/
m_openKeys = new QAction (tr("Open Keyboard..."),
Resource::loadPixmap( "down" ),
QString::null, 0, this, 0);
m_openKeys->setToggleAction(true);
connect (m_openKeys, SIGNAL(toggled(bool)),
this, SLOT(slotOpenKeb(bool)));
m_openKeys->addTo(m_icons);
/* insert the submenu */
m_console->insertItem(tr("New from Profile"), m_sessionsPop,
-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);
/*
@@ -180,24 +200,58 @@ QList<Session> MainWindow::sessions() {
}
void MainWindow::slotNew() {
qWarning("New Connection");
ProfileEditorDialog dlg(factory() );
int ret = dlg.exec();
if ( ret == QDialog::Accepted ) {
create( dlg.profile() );
}
}
+void MainWindow::slotRecordScript() {
+ if (currentSession()) {
+ currentSession()->emulationLayer()->startRecording();
+ }
+}
+
+void MainWindow::slotSaveScript() {
+ if (currentSession() && currentSession()->emulationLayer()->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();
+ }
+ }
+}
+
+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);
+ }
+ }
+}
+
void MainWindow::slotConnect() {
if ( currentSession() )
currentSession()->layer()->open();
}
void MainWindow::slotDisconnect() {
if ( currentSession() )
currentSession()->layer()->close();
}
void MainWindow::slotTerminate() {
if ( currentSession() )
diff --git a/noncore/apps/opie-console/mainwindow.h b/noncore/apps/opie-console/mainwindow.h
index 73bb285..94144a4 100644
--- a/noncore/apps/opie-console/mainwindow.h
+++ b/noncore/apps/opie-console/mainwindow.h
@@ -50,25 +50,27 @@ public:
TabWidget* tabWidget();
private slots:
void slotNew();
void slotConnect();
void slotDisconnect();
void slotTerminate();
void slotConfigure();
void slotClose();
void slotProfile(int);
void slotTransfer();
void slotOpenKeb(bool);
-
+ void slotRecordScript();
+ void slotSaveScript();
+ void slotRunScript();
private:
void initUI();
void populateProfiles();
void create( const Profile& );
/**
* the current session
*/
Session* m_curSession;
/**
* the session list
*/
@@ -79,24 +81,28 @@ private:
*/
MetaFactory* m_factory;
ProfileManager* m_manager;
TabWidget* m_consoleWindow;
QToolBar* m_tool;
QToolBar* m_icons;
QToolBar* m_keyBar;
QMenuBar* m_bar;
QPopupMenu* m_console;
QPopupMenu* m_settings;
QPopupMenu* m_sessionsPop;
+ QPopupMenu* m_scripts;
QAction* m_connect;
QAction* m_disconnect;
QAction* m_terminate;
QAction* m_transfer;
QAction* m_setProfiles;
QAction* m_openKeys;
+ QAction* m_recordScript;
+ QAction* m_saveScript;
+ QAction* m_runScript;
FunctionKeyboard *m_kb;
};
#endif
diff --git a/noncore/apps/opie-console/opie-console.pro b/noncore/apps/opie-console/opie-console.pro
index b07f10a..8e39a48 100644
--- a/noncore/apps/opie-console/opie-console.pro
+++ b/noncore/apps/opie-console/opie-console.pro
@@ -21,25 +21,25 @@ HEADERS = io_layer.h io_serial.h io_irda.h io_bt.h\
keytrans.h \
widget_layer.h \
transferdialog.h \
profiledialogwidget.h \
profileeditordialog.h \
default.h \
terminalwidget.h \
iolayerbase.h \
serialconfigwidget.h irdaconfigwidget.h \
btconfigwidget.h modemconfigwidget.h \
atconfigdialog.h dialdialog.h \
emulation_widget.h procctl.h \
- function_keyboard.h
+ function_keyboard.h script.h
SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
file_layer.cpp filetransfer.cpp \
main.cpp \
metafactory.cpp \
session.cpp \
mainwindow.cpp \
profile.cpp \
profileconfig.cpp \
profilemanager.cpp \
tabwidget.cpp \
configdialog.cpp \
@@ -49,20 +49,20 @@ SOURCES = io_layer.cpp io_serial.cpp io_irda.cpp io_bt.cpp \
screen.cpp \
keytrans.cpp \
widget_layer.cpp \
transferdialog.cpp \
profiledialogwidget.cpp \
profileeditordialog.cpp \
terminalwidget.cpp \
iolayerbase.cpp \
serialconfigwidget.cpp irdaconfigwidget.cpp \
btconfigwidget.cpp modemconfigwidget.cpp \
atconfigdialog.cpp dialdialog.cpp \
emulation_widget.cpp default.cpp procctl.cpp \
- function_keyboard.cpp
+ function_keyboard.cpp script.cpp
INTERFACES = configurebase.ui editbase.ui
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
TARGET = opie-console
diff --git a/noncore/apps/opie-console/script.cpp b/noncore/apps/opie-console/script.cpp
new file mode 100644
index 0000000..a09fab6
--- a/dev/null
+++ b/noncore/apps/opie-console/script.cpp
@@ -0,0 +1,30 @@
+#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());
+ }
+}
+
+void Script::saveTo(const QString fileName) const {
+ QFile file(fileName);
+ file.open(IO_WriteOnly);
+ file.writeBlock(m_script.ascii(), m_script.length());
+ file.close();
+}
+
+
+void Script::appendString(const QString string) {
+ m_script += string;
+}
+
+QString Script::script() const {
+ return m_script;
+}
diff --git a/noncore/apps/opie-console/script.h b/noncore/apps/opie-console/script.h
new file mode 100644
index 0000000..dc2351b
--- a/dev/null
+++ b/noncore/apps/opie-console/script.h
@@ -0,0 +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);
+
+ /* Save this script to a file */
+ void saveTo(const QString fileName) const;
+
+ /* Return the script's content */
+ QString script() const;
+protected:
+ QString m_script;
+};
+
+
+#endif /* CONSOLE_SCRIPT_H */