summaryrefslogtreecommitdiff
authorzecke <zecke>2002-10-15 13:02:56 (UTC)
committer zecke <zecke>2002-10-15 13:02:56 (UTC)
commit09ba4d2c79a41b185902519639032a49c85deadb (patch) (side-by-side diff)
treef1d9676bf3401bb93e527c8608a9307bf4adf244
parentb555d0c687db83cde89f1a75fccbd59723878621 (diff)
downloadopie-09ba4d2c79a41b185902519639032a49c85deadb.zip
opie-09ba4d2c79a41b185902519639032a49c85deadb.tar.gz
opie-09ba4d2c79a41b185902519639032a49c85deadb.tar.bz2
Add a Feature Support BitArray to the IOLayer
This way we know what an IOLayer supports Adjust IOSerial and MyPty to that change Fix the after close window the previous session window is empty bug in Mainwindow::remove we had a problem first we removed the currentSession from the tab and then deleted the session The problem is that removePage on OTabWidget does signal currentChanged so we did not delete the session intended but the wrong one because m_curSession got adjusted after a removePage... 3rd fix the close and reopen bug in MyPty
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-console/BUGS9
-rw-r--r--noncore/apps/opie-console/MyPty.cpp23
-rw-r--r--noncore/apps/opie-console/MyPty.h2
-rw-r--r--noncore/apps/opie-console/io_layer.h14
-rw-r--r--noncore/apps/opie-console/io_serial.cpp7
-rw-r--r--noncore/apps/opie-console/io_serial.h4
-rw-r--r--noncore/apps/opie-console/mainwindow.cpp10
-rw-r--r--noncore/apps/opie-console/profilemanager.cpp15
-rw-r--r--noncore/apps/opie-console/session.cpp6
-rw-r--r--noncore/apps/opie-console/session.h1
-rw-r--r--noncore/apps/opie-console/tabwidget.cpp1
11 files changed, 72 insertions, 20 deletions
diff --git a/noncore/apps/opie-console/BUGS b/noncore/apps/opie-console/BUGS
new file mode 100644
index 0000000..ffaceef
--- a/dev/null
+++ b/noncore/apps/opie-console/BUGS
@@ -0,0 +1,9 @@
+Ok we all know we write perfect code
+but sometimes the compiler produces bad code
+and we need to work around some compiler bugs!! -zecke
+
+MyPty is broken in some ways
+ if you do connect/disconnect/connect sh will be executed in the
+ process of opie-console.... funny aye?
+
+OTabWidget seems to give us problems too
diff --git a/noncore/apps/opie-console/MyPty.cpp b/noncore/apps/opie-console/MyPty.cpp
index b6ae1d9..565d03f 100644
--- a/noncore/apps/opie-console/MyPty.cpp
+++ b/noncore/apps/opie-console/MyPty.cpp
@@ -108,28 +108,31 @@ void MyPty::setSize(int lines, int columns)
void MyPty::donePty()
{
// This is code from the Qt DumbTerminal example
int status = 0;
::close(m_fd);
if (m_cpid) {
kill(m_cpid, SIGHUP);
//waitpid(m_cpid, &status, 0);
delete m_sn_e;
+ delete m_sn_r;
m_sn_e = 0l;
+ m_sn_r = 0l;
}
m_cpid = 0;
+ m_fd = -1;
// emit done(status);
}
const char* MyPty::deviceName()
{
return m_ttynam;
}
void MyPty::error()
{
@@ -176,28 +179,29 @@ int MyPty::run(const char* cmd, QStrList &, const char*, int)
if (getuid() == 0) {
char msg[] = "WARNING: You are running this shell as root!\n";
write(ttyfd, msg, sizeof(msg));
}
execl(cmd, cmd, 0);
donePty();
exit(-1);
}
// parent - continue as a widget
- QSocketNotifier* sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
+ delete m_sn_r;
+ m_sn_r = new QSocketNotifier(m_fd,QSocketNotifier::Read,this);
delete m_sn_e;
m_sn_e = new QSocketNotifier(m_fd,QSocketNotifier::Exception,this);
- connect(sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
+ connect(m_sn_r,SIGNAL(activated(int)),this,SLOT(readPty()));
connect(m_sn_e,SIGNAL(activated(int)),this,SLOT(error()));
return 0;
}
int MyPty::openPty()
{
// This is code from the Qt DumbTerminal example
int ptyfd = -1;
#ifdef HAVE_OPENPTY
int ttyfd;
@@ -212,62 +216,67 @@ int MyPty::openPty()
sprintf(m_ttynam,"/dev/tty%c%c",*c0,*c1);
if ((ptyfd = ::open(m_ptynam,O_RDWR)) >= 0) {
if (geteuid() != 0 && !access(m_ttynam,R_OK|W_OK) == 0) {
::close(ptyfd);
ptyfd = -1;
}
}
}
}
#endif
if ( ptyfd < 0 ) {
- qApp->exit(1);
+// qApp->exit(1);
return -1;
}
return ptyfd;
}
/*!
Create an instance.
*/
MyPty::MyPty(const Profile&) : m_cpid(0)
{
m_sn_e = 0l;
+ m_sn_r = 0l;
m_fd = openPty();
ProcCtl* ctl = ProcCtl::self();
}
/*!
Destructor.
Note that the related client program is not killed
(yet) when a instance is deleted.
*/
MyPty::~MyPty()
{
donePty();
}
QString MyPty::identifier()const {
return QString::fromLatin1("term");
}
QString MyPty::name()const{
return identifier();
}
bool MyPty::open() {
+ if (m_fd < 0)
+ m_fd = openPty();
+
start();
return true;
}
void MyPty::close() {
donePty();
+ m_fd = openPty();
}
void MyPty::reload( const Profile& ) {
}
/*! sends len bytes through the line */
void MyPty::send(const QByteArray& ar)
{
#ifdef VERBOSE_DEBUG
// verbose debug
printf("sending bytes:\n");
for (uint i = 0; i < ar.count(); i++)
printf("%c", ar[i]);
@@ -277,33 +286,39 @@ void MyPty::send(const QByteArray& ar)
::write(m_fd, ar.data(), ar.count());
}
/*! indicates that a block of data is received */
void MyPty::readPty()
{
QByteArray buf(4096);
int len = ::read( m_fd, buf.data(), 4096 );
if (len == -1 || len == 0) {
donePty();
- delete sender();
return;
}
if (len < 0)
return;
buf.resize(len);
emit received(buf);
#ifdef VERBOSE_DEBUG
// verbose debug
printf("read bytes:\n");
for (uint i = 0; i < buf.count(); i++)
printf("%c", buf[i]);
printf("\n");
#endif
}
+QBitArray MyPty::supports()const {
+ QBitArray ar(3);
+ ar[0] = 1;
+ ar[1] = 0;
+ ar[2] = 0;
+ return ar;
+}
diff --git a/noncore/apps/opie-console/MyPty.h b/noncore/apps/opie-console/MyPty.h
index 3166fa0..ad271df 100644
--- a/noncore/apps/opie-console/MyPty.h
+++ b/noncore/apps/opie-console/MyPty.h
@@ -32,24 +32,25 @@ class QSocketNotifier;
class MyPty : public IOLayer
{
Q_OBJECT
public:
MyPty(const Profile&);
~MyPty();
QString identifier()const;
QString name()const;
+ QBitArray supports()const;
public slots:
/*!
having a `run' separate from the constructor allows to make
the necessary connections to the signals and slots of the
instance before starting the execution of the client.
*/
void start();
int run(const char* pgm, QStrList & args , const char* term, int addutmp);
bool open();
void close();
void reload( const Profile& );
@@ -83,15 +84,16 @@ protected slots:
void donePty();
private:
int openPty();
private:
char m_ptynam[16]; // "/dev/ptyxx" | "/dev/ptmx"
char m_ttynam[16]; // "/dev/ttyxx" | "/dev/pts/########..."
int m_fd;
int m_cpid;
QSocketNotifier* m_sn_e;
+ QSocketNotifier* m_sn_r;
};
#endif
diff --git a/noncore/apps/opie-console/io_layer.h b/noncore/apps/opie-console/io_layer.h
index 5f2fa3c..4977e94 100644
--- a/noncore/apps/opie-console/io_layer.h
+++ b/noncore/apps/opie-console/io_layer.h
@@ -1,37 +1,45 @@
#ifndef OPIE_IO_LAYER_H
#define OPIE_IO_LAYER_H
+#include <qbitarray.h>
#include <qobject.h>
+
+
#include <qpe/config.h>
#include "profile.h"
/**
* This is the base class for IO Layers
* It will used to sent and recv data( QByteArray )
* it
*/
class IOLayer : public QObject {
Q_OBJECT
public:
enum Error {
NoError = -1,
Refuse = 0,
CouldNotOpen =1,
ClosedUnexpected =2,
ClosedError =3,
Terminate = 4
/* add more errors here */
};
+ enum Feature {
+ AutoConnect = 0,
+ TransferFile =1,
+ Close =2
+ };
/**
* a small c'tor
*/
IOLayer();
/**
* create an IOLayer instance from a config file
* the currently set group stores the profile/session
* information
*/
IOLayer( const Profile& );
@@ -56,38 +64,44 @@ public:
* do any ioctling on it...
* and it'll stop listening to the before opened
* device
*/
virtual int rawIO()const;
/**
* will close the rawIO stuff
* and will listen to it's data again...
*/
virtual void closeRawIO(int);
+ /**
+ * What does the IOLayer support?
+ * Bits are related to features
+ */
+ virtual QBitArray supports()const = 0;
signals:
/**
* received input as QCString
*/
virtual void received( const QByteArray& );
/**
* an error occured
* int for the error number
* and QString for a text
*/
virtual void error( int, const QString& );
+ virtual void closed();
public slots:
/**
* send a QCString to the device
*/
virtual void send( const QByteArray& ) = 0;
/**
* bool open
*/
virtual bool open() = 0;
/**
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp
index a4a6f0b..c10d5a8 100644
--- a/noncore/apps/opie-console/io_serial.cpp
+++ b/noncore/apps/opie-console/io_serial.cpp
@@ -178,12 +178,19 @@ int IOSerial::rawIO()const {
int fd = ::open(m_device, O_RDWR );
return fd;
};
void IOSerial::closeRawIO(int fd) {
if (m_read )
connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived()));
if (m_error )
connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured()));
::close( fd );
}
+QBitArray IOSerial::supports()const {
+ QBitArray ar(3);
+ ar[0] = ar[2] = 0;
+ ar[1] = 1;
+
+ return ar;
+}
diff --git a/noncore/apps/opie-console/io_serial.h b/noncore/apps/opie-console/io_serial.h
index facbbc1..b1d1be1 100644
--- a/noncore/apps/opie-console/io_serial.h
+++ b/noncore/apps/opie-console/io_serial.h
@@ -28,27 +28,29 @@ public:
enum Flow {
FlowHW = 0x01,
FlowSW = 0x02
};
IOSerial(const Profile &);
~IOSerial();
QString identifier() const;
QString name() const;
int rawIO()const;
void closeRawIO(int fd );
-signals:
+ QBitArray supports()const;
+/*signals:
void received(const QByteArray &);
void error(int, const QString &);
+*/
public slots:
void send(const QByteArray &);
bool open();
void close();
void reload(const Profile &);
protected:
int baud(int baud) const;
protected slots:
void dataArrived();
void errorOccured();
protected:
QSocketNotifier *m_read;
diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp
index 94c99bc..29dbcf3 100644
--- a/noncore/apps/opie-console/mainwindow.cpp
+++ b/noncore/apps/opie-console/mainwindow.cpp
@@ -351,29 +351,30 @@ void MainWindow::slotConfigure() {
}
/*
* 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() );
tabWidget()->remove( currentSession() );
/*it's autodelete */
- m_sessions.remove( m_curSession );
- m_curSession = m_sessions.first();
- tabWidget()->setCurrent( m_curSession );
+ 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 );
}
@@ -386,25 +387,25 @@ void MainWindow::slotClose() {
*/
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("Cannot open session: Not all components were found."));
+ QObject::tr("<qt>Cannot open session: Not all components were found.</qt>"));
//if(ses) delete ses;
return;
}
m_sessions.append( ses );
tabWidget()->add( ses );
m_curSession = ses;
// dicide if its a local term ( then no connction and no tranfer), maybe make a wrapper method out of it
m_connect->setEnabled( true );
m_disconnect->setEnabled( false );
m_terminate->setEnabled( true );
@@ -424,24 +425,25 @@ void MainWindow::slotTransfer()
dlg.exec();
}
}
void MainWindow::slotOpenKeb(bool state) {
if (state) m_keyBar->show();
else m_keyBar->hide();
}
void MainWindow::slotSessionChanged( Session* ses ) {
+ qWarning("changed!");
if ( ses ) {
m_curSession = ses;
if ( m_curSession->isConnected() ) {
m_connect->setEnabled( false );
m_disconnect->setEnabled( true );
} else {
m_connect->setEnabled( true );
m_disconnect->setEnabled( false );
}
}
}
diff --git a/noncore/apps/opie-console/profilemanager.cpp b/noncore/apps/opie-console/profilemanager.cpp
index e5aedb6..7c15560 100644
--- a/noncore/apps/opie-console/profilemanager.cpp
+++ b/noncore/apps/opie-console/profilemanager.cpp
@@ -1,16 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <qfile.h>
+#include <qhbox.h>
#include <qlayout.h>
#include <qwidgetstack.h>
#include <qpe/config.h>
#include "emulation_handler.h"
#include "widget_layer.h"
#include "emulation_widget.h"
#include "metafactory.h"
#include "profileconfig.h"
#include "profilemanager.h"
@@ -76,37 +77,29 @@ Session* ProfileManager::fromProfile( const Profile& prof, QWidget* parent) {
prof.writeEntry("Baud", 115200 );
prof.setIOLayer("serial");
prof.setName( "test");
*/
Session* session = new Session();
session->setName( prof.name() );
/* translate the internal name to the external */
session->setIOLayer(m_fact->newIOLayer( m_fact->external(prof.ioLayerName()) ,
prof) );
QWidgetStack *stack = new QWidgetStack( parent );
session->setWidgetStack( stack );
- QWidget* dummy = new QWidget( stack );
- QHBoxLayout* lay = new QHBoxLayout( dummy );
- stack->addWidget( dummy, 0 );
- stack->raiseWidget( 0 );
+ QWidget* dummy = new QHBox( stack );
+ stack->raiseWidget( dummy );
+
EmulationHandler* handler = new EmulationHandler(prof,dummy );
session->setEmulationHandler( handler );
- lay->addWidget( handler->widget() );
-// WidgetLayer* wid = new EmulationWidget( prof, dummy );
-// lay->addWidget( wid );
-
-// session->setEmulationWidget( wid );
-// session->setEmulationLayer( m_fact->newEmulationLayer( m_fact->external( prof.terminalName() ),
-// wid ) );
session->connect();
return session;
}
void ProfileManager::save( ) {
QFile::remove( (QString(getenv("HOME") )+ "/Settings/opie-console-profiles.conf" ) );
ProfileConfig conf("opie-console-profiles");
Profile::ValueList::Iterator it2;
for (it2 = m_list.begin(); it2 != m_list.end(); ++it2 ) {
conf.setGroup( (*it2).name() );
/* now the config stuff */
diff --git a/noncore/apps/opie-console/session.cpp b/noncore/apps/opie-console/session.cpp
index e53dbc4..aad100d 100644
--- a/noncore/apps/opie-console/session.cpp
+++ b/noncore/apps/opie-console/session.cpp
@@ -27,24 +27,30 @@ Session::~Session() {
QString Session::name()const {
return m_name;
}
QWidgetStack* Session::widgetStack() {
return m_widget;
}
IOLayer* Session::layer() {
return m_layer;
}
EmulationHandler* Session::emulationHandler() {
return m_emu;
}
+QWidget* Session::widget() {
+ if (!m_emu )
+ return 0l;
+
+ return m_emu->widget();
+}
/*
WidgetLayer* Session::emulationWidget() {
return m_widLay;
}
*/
void Session::connect() {
if ( !m_layer || !m_emu )
return;
m_connected = true;
QObject::connect(m_layer, SIGNAL(received(const QByteArray&) ),
diff --git a/noncore/apps/opie-console/session.h b/noncore/apps/opie-console/session.h
index a1121d3..ff92df3 100644
--- a/noncore/apps/opie-console/session.h
+++ b/noncore/apps/opie-console/session.h
@@ -25,24 +25,25 @@ public:
* return the name of the session
*/
QString name()const;
/**
* return the widgetstack
* this is used to be semi modal
* for FileTransfer
*
* semi modal == SessionModal
*/
QWidgetStack* widgetStack();
+ QWidget* widget();
/**
* return the layer
*/
IOLayer* layer();
EmulationHandler* emulationHandler();
/*
* connects the data flow from
* the IOLayer to the EmulationLayer
*/
diff --git a/noncore/apps/opie-console/tabwidget.cpp b/noncore/apps/opie-console/tabwidget.cpp
index 8a691f9..419f8ac 100644
--- a/noncore/apps/opie-console/tabwidget.cpp
+++ b/noncore/apps/opie-console/tabwidget.cpp
@@ -2,24 +2,25 @@
#include "tabwidget.h"
TabWidget::TabWidget( QWidget* parent, const char* name )
: OTabWidget( parent, name ) {
connect(this, SIGNAL( currentChanged(QWidget*) ),
this, SLOT( slotCurChanged(QWidget*) ) );
}
TabWidget::~TabWidget() {
}
void TabWidget::add( Session* ses ) {
+ qWarning("session ses " + ses->name() );
if ( !ses->widgetStack() ) return;
//reparent( ses->widgetStack(), QPoint() );
addTab( ses->widgetStack(), "console/konsole", ses->name() );
//addTab( ses->widgetStack(), ses->name() );
m_map.insert( ses->widgetStack(), ses );
}
void TabWidget::remove( Session* ses ) {
m_map.remove( ses->widgetStack() );
removePage( ses->widgetStack() );
}