Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 0649514..9ec5bf8 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp @@ -18,12 +18,16 @@ #include "bluebase.h" #include "scandialog.h" #include "hciconfwrapper.h" #include "devicehandler.h" #include "btconnectionitem.h" #include "rfcommassigndialogimpl.h" +#include "forwarder.h" +#include <termios.h> +#include <string.h> +#include <errno.h> /* OPIE */ #include <qpe/qpeapplication.h> #include <qpe/resource.h> #include <qpe/config.h> #include <opie2/odebug.h> @@ -38,12 +42,13 @@ using namespace Opie::Core; #include <qimage.h> #include <qpixmap.h> #include <qtabwidget.h> #include <qscrollview.h> #include <qvbox.h> #include <qmessagebox.h> +#include <qcombobox.h> #include <qcheckbox.h> #include <qlineedit.h> #include <qlistview.h> #include <qdir.h> #include <qpopupmenu.h> #include <qtimer.h> @@ -52,12 +57,22 @@ using namespace Opie::Core; /* STD */ #include <remotedevice.h> #include <services.h> #include <stdlib.h> using namespace OpieTooth; +//Array of possible speeds of the serial port +struct SerSpeed { + const char* str; //string value + int val; //value itself +} speeds[] = { + { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, + { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, + { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, + { "115200", B115200} +}; BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) : BluetoothBase( parent, name, fl ) { m_localDevice = new Manager( "hci0" ); @@ -75,12 +90,13 @@ BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) connect( m_localDevice, SIGNAL( available(const QString&,bool) ), this, SLOT( deviceActive(const QString&,bool) ) ); connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), this, SLOT( addSignalStrength(const QString&,const QString&) ) ); + connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); // let hold be rightButtonClicked() QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); //Load all icons needed @@ -105,12 +121,18 @@ BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) m_iconLoader = new BTIconLoader(); writeToHciConfig(); addConnectedDevices(); readSavedDevices(); addServicesToDevices(); QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); + forwarder = NULL; + serDevName->setText(tr("/dev/ircomm0")); + for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) { + serSpeed->insertItem(speeds[i].str); + } + serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1); } /** * Reads all options from the config file */ void BlueBase::readConfig() @@ -677,6 +699,45 @@ bool BlueBase::find( const RemoteDevice& rem ) device = (BTDeviceItem*)item; if ( rem.equals( device->remoteDevice() ) ) return true; } return false; // not found } + +/** + * Start process of the cell phone forwarding + */ +void BlueBase::doForward() +{ + if (forwarder && forwarder->isRunning()) { + runButton->setText("start gateway"); + forwarder->stop(); + delete forwarder; + forwarder = NULL; + return; + } + QString str = serDevName->text(); + forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); + connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)), + this, SLOT(forwardExited(Opie::Core::OProcess*))); + if (forwarder->start(OProcess::NotifyOnExit) < 0) { + QMessageBox::critical(this, tr("Forwarder Error"), + tr("Forwarder start error:") + tr(strerror(errno))); + return; + } + runButton->setText("stop gateway"); +} + +/** + * React on the process end + */ +void BlueBase::forwardExit(Opie::Core::OProcess* proc) +{ + if (proc->exitStatus() != 0) + QMessageBox::critical(this, tr("Forwarder Error"), + tr("Forwarder start error")); + delete proc; + forwarder = NULL; + runButton->setText("start gateway"); +} + +//eof |