author | zecke <zecke> | 2002-10-09 01:58:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-09 01:58:20 (UTC) |
commit | 849316bd18f06e43e7dfa2f107ad96d5bedbe7f1 (patch) (side-by-side diff) | |
tree | f793cbfc60377d2dbb2cd5b1066bdadec5738dc4 | |
parent | a74bf68065b94efaacb73736c7127ccb74474645 (diff) | |
download | opie-849316bd18f06e43e7dfa2f107ad96d5bedbe7f1.zip opie-849316bd18f06e43e7dfa2f107ad96d5bedbe7f1.tar.gz opie-849316bd18f06e43e7dfa2f107ad96d5bedbe7f1.tar.bz2 |
IOSerial fixlet
if failed to ioctl m_fd is != 0
so set it 0
and initialize m_read, m_error properly
TabWidget was a OTabWidget again but there is a bug somewhere in the
removePage code. I hopefully kindly asked drw to take a look at it
MainWindiw
Close does not terminate
Screen is funny to look at... everytime a different background.
when using QTabWidget I see nothing when using OTabWidget i've vertical scrollbars and see the content
-rw-r--r-- | noncore/apps/opie-console/io_serial.cpp | 3 | ||||
-rw-r--r-- | noncore/apps/opie-console/mainwindow.cpp | 7 |
2 files changed, 7 insertions, 3 deletions
diff --git a/noncore/apps/opie-console/io_serial.cpp b/noncore/apps/opie-console/io_serial.cpp index b495f39..77ced85 100644 --- a/noncore/apps/opie-console/io_serial.cpp +++ b/noncore/apps/opie-console/io_serial.cpp @@ -1,168 +1,171 @@ #include <fcntl.h> #include <termios.h> #include <errno.h> #include <unistd.h> #include "io_serial.h" IOSerial::IOSerial(const Profile &config) : IOLayer(config) { + m_read = 0l; + m_error = 0l; m_fd = 0; reload(config); } IOSerial::~IOSerial() { if (m_fd) { close(); } } void IOSerial::send(const QByteArray &data) { if (m_fd) { write(m_fd, data.data(), data.size()); } else { emit error(Refuse, tr("Not connected")); } } void IOSerial::close() { if (m_fd) { delete m_read; delete m_error; ::close(m_fd); m_fd = 0; } else { emit error(Refuse, tr("Not connected")); } } bool IOSerial::open() { if (!m_fd) { struct termios tty; m_fd = ::open(m_device, O_RDWR | O_NOCTTY | O_NONBLOCK); if (m_fd < 0) { emit error(CouldNotOpen, strerror(errno)); return FALSE; } tcgetattr(m_fd, &tty); /* Baud rate */ int speed = baud(m_baud); if (speed == -1) { emit error(Refuse, tr("Invalid baud rate")); } cfsetospeed(&tty, speed); cfsetispeed(&tty, speed); /* Take care of Space / Mark parity */ if (m_dbits == 7 && (m_parity == ParitySpace || m_parity == ParityMark)) { m_dbits = 8; } /* Data bits */ switch (m_dbits) { case 5: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS5; break; case 6: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS6; break; case 7: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS7; break; case 8: tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; break; default: break; } /* Raw, no echo mode */ tty.c_iflag = IGNBRK; tty.c_lflag = 0; tty.c_oflag = 0; tty.c_cflag |= CLOCAL | CREAD; /* Stop bits */ if (m_sbits == 2) { tty.c_cflag |= CSTOPB; } else { tty.c_cflag &= ~CSTOPB; } tty.c_cc[VMIN] = 1; tty.c_cc[VTIME] = 5; /* Flow control */ if (m_flow & FlowSW) tty.c_iflag |= IXON | IXOFF; else tty.c_iflag &= ~(IXON|IXOFF|IXANY); if (m_flow & FlowHW) tty.c_cflag |= CRTSCTS; else tty.c_cflag &= ~CRTSCTS; /* Parity */ tty.c_cflag &= ~(PARENB | PARODD); if (m_parity & ParityEven) tty.c_cflag |= PARENB; else if (m_parity & ParityOdd) tty.c_cflag |= (PARENB | PARODD); /* Set the changes */ tcsetattr(m_fd, TCSANOW, &tty); /* Notifications on read & errors */ m_read = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); m_error = new QSocketNotifier(m_fd, QSocketNotifier::Exception, this); connect(m_read, SIGNAL(activated(int)), this, SLOT(dataArrived())); connect(m_error, SIGNAL(activated(int)), this, SLOT(errorOccured())); return TRUE; } else { emit error(Refuse, tr("Device is already connected")); + m_fd = 0; return FALSE; } } void IOSerial::reload(const Profile &config) { m_device = config.readEntry("Device", SERIAL_DEFAULT_DEVICE); m_baud = config.readNumEntry("Baud", SERIAL_DEFAULT_BAUD); m_parity = config.readNumEntry("Parity", SERIAL_DEFAULT_PARITY); m_dbits = config.readNumEntry("DataBits", SERIAL_DEFAULT_DBITS); m_sbits = config.readNumEntry("StopBits", SERIAL_DEFAULT_SBITS); m_flow = config.readNumEntry("Flow", SERIAL_DEFAULT_FLOW); } int IOSerial::baud(int baud) const { switch (baud) { case 300: return B300; break; case 600: return B600; break; case 1200: return B1200; break; case 2400: return B2400; break; case 4800: return B4800; break; case 9600: return B9600; break; case 19200: return B19200; break; case 38400: return B38400; break; case 57600: return B57600; break; case 115200: return B115200; break; } return -1; } void IOSerial::errorOccured() { emit error(ClosedUnexpected, strerror(errno)); close(); } void IOSerial::dataArrived() { QByteArray array; char buf[4096]; int len = read(m_fd, buf, 4096); if (len == 0) close(); if (len < 0) return; array.setRawData(buf, len); emit received(array); } QString IOSerial::identifier() const { return "serial"; } QString IOSerial::name() const { return "RS232 Serial IO Layer"; } diff --git a/noncore/apps/opie-console/mainwindow.cpp b/noncore/apps/opie-console/mainwindow.cpp index aeb3742..0bd6a13 100644 --- a/noncore/apps/opie-console/mainwindow.cpp +++ b/noncore/apps/opie-console/mainwindow.cpp @@ -1,216 +1,217 @@ #include <qaction.h> #include <qmenubar.h> #include <qlabel.h> #include <qpopupmenu.h> #include <qtoolbar.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" 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 ); m_tool = new QToolBar( this ); m_tool->setHorizontalStretchable( TRUE ); m_bar = new QMenuBar( m_tool ); m_console = new QPopupMenu( this ); m_sessionsPop= new QPopupMenu( this ); m_settings = new QPopupMenu( this ); /* * new Action for new sessions */ QAction* a = new QAction(); a->setText( tr("New Connection") ); a->addTo( m_console ); connect(a, SIGNAL(activated() ), this, SLOT(slotNew() ) ); /* * connect action */ m_connect = new QAction(); m_connect->setText( tr("Connect") ); m_connect->addTo( m_console ); connect(m_connect, SIGNAL(activated() ), this, SLOT(slotConnect() ) ); /* * disconnect action */ m_disconnect = new QAction(); m_disconnect->setText( tr("Disconnect") ); m_disconnect->addTo( m_console ); connect(m_disconnect, SIGNAL(activated() ), this, SLOT(slotDisconnect() ) ); /* * terminate action */ m_terminate = new QAction(); m_terminate->setText( tr("Terminate") ); m_terminate->addTo( m_console ); - connect(m_disconnect, SIGNAL(activated() ), + connect(m_terminate, SIGNAL(activated() ), this, SLOT(slotTerminate() ) ); a = new QAction(); a->setText( tr("Close Window") ); a->addTo( m_console ); connect(a, SIGNAL(activated() ), this, SLOT(slotClose() ) ); /* * the settings action */ m_setProfiles = new QAction(); m_setProfiles->setText( tr("Configure Profiles") ); m_setProfiles->addTo( m_settings ); connect( m_setProfiles, SIGNAL(activated() ), this, SLOT(slotConfigure() ) ); /* 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 settings menu */ m_bar->insertItem( tr("Settings"), m_settings ); /* * connect to the menu activation */ connect( m_sessionsPop, SIGNAL(activated( int ) ), this, SLOT(slotProfile( int ) ) ); m_consoleWindow = new TabWidget( this, "blah"); 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() { qWarning("New Connection"); ProfileEditorDialog dlg(factory() ); int ret = dlg.exec(); if ( ret == QDialog::Accepted ) { create( dlg.profile() ); } } void MainWindow::slotConnect() { if ( currentSession() ) currentSession()->layer()->open(); } void MainWindow::slotDisconnect() { if ( currentSession() ) currentSession()->layer()->close(); } void MainWindow::slotTerminate() { if ( currentSession() ) currentSession()->layer()->close(); slotClose(); /* FIXME move to the next session */ } void MainWindow::slotConfigure() { qWarning("configure"); ConfigDialog conf( manager()->all(), factory() ); conf.showMaximized(); int ret = conf.exec(); if ( QDialog::Accepted == ret ) { qWarning("conf %d", conf.list().count() ); manager()->setProfiles( conf.list() ); populateProfiles(); } } /* * we will remove * this window from the tabwidget * remove it from the list * delete it * and set the currentSession() */ void MainWindow::slotClose() { + qWarning("close"); if (!currentSession() ) return; tabWidget()->remove( currentSession() ); - tabWidget()->setCurrent( m_sessions.first() ); + /*it's autodelete */ m_sessions.remove( m_curSession ); - delete m_curSession; m_curSession = m_sessions.first(); + tabWidget()->setCurrent( m_curSession ); } /* * 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() ); m_sessions.append( ses ); tabWidget()->add( ses ); m_curSession = ses; } |