summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/bluebase.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp61
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
@@ -12,81 +12,97 @@
12 * it under the terms of the GNU General Public License as published by * 12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or * 13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. * 14 * (at your option) any later version. *
15 * * 15 * *
16 ***************************************************************************/ 16 ***************************************************************************/
17 17
18#include "bluebase.h" 18#include "bluebase.h"
19#include "scandialog.h" 19#include "scandialog.h"
20#include "hciconfwrapper.h" 20#include "hciconfwrapper.h"
21#include "devicehandler.h" 21#include "devicehandler.h"
22#include "btconnectionitem.h" 22#include "btconnectionitem.h"
23#include "rfcommassigndialogimpl.h" 23#include "rfcommassigndialogimpl.h"
24#include "forwarder.h"
25#include <termios.h>
26#include <string.h>
27#include <errno.h>
24 28
25/* OPIE */ 29/* OPIE */
26#include <qpe/qpeapplication.h> 30#include <qpe/qpeapplication.h>
27#include <qpe/resource.h> 31#include <qpe/resource.h>
28#include <qpe/config.h> 32#include <qpe/config.h>
29#include <opie2/odebug.h> 33#include <opie2/odebug.h>
30using namespace Opie::Core; 34using namespace Opie::Core;
31 35
32/* QT */ 36/* QT */
33#include <qframe.h> 37#include <qframe.h>
34#include <qlabel.h> 38#include <qlabel.h>
35#include <qpushbutton.h> 39#include <qpushbutton.h>
36#include <qlayout.h> 40#include <qlayout.h>
37#include <qvariant.h> 41#include <qvariant.h>
38#include <qimage.h> 42#include <qimage.h>
39#include <qpixmap.h> 43#include <qpixmap.h>
40#include <qtabwidget.h> 44#include <qtabwidget.h>
41#include <qscrollview.h> 45#include <qscrollview.h>
42#include <qvbox.h> 46#include <qvbox.h>
43#include <qmessagebox.h> 47#include <qmessagebox.h>
48#include <qcombobox.h>
44#include <qcheckbox.h> 49#include <qcheckbox.h>
45#include <qlineedit.h> 50#include <qlineedit.h>
46#include <qlistview.h> 51#include <qlistview.h>
47#include <qdir.h> 52#include <qdir.h>
48#include <qpopupmenu.h> 53#include <qpopupmenu.h>
49#include <qtimer.h> 54#include <qtimer.h>
50#include <qlist.h> 55#include <qlist.h>
51 56
52/* STD */ 57/* STD */
53#include <remotedevice.h> 58#include <remotedevice.h>
54#include <services.h> 59#include <services.h>
55#include <stdlib.h> 60#include <stdlib.h>
56 61
57using namespace OpieTooth; 62using namespace OpieTooth;
63//Array of possible speeds of the serial port
64struct SerSpeed {
65 const char* str; //string value
66 int val; //value itself
67} speeds[] = {
68 { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 },
69 { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 },
70 { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 },
71 { "115200", B115200}
72};
58 73
59BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 74BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
60 : BluetoothBase( parent, name, fl ) 75 : BluetoothBase( parent, name, fl )
61{ 76{
62 m_localDevice = new Manager( "hci0" ); 77 m_localDevice = new Manager( "hci0" );
63 78
64 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); 79 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
65 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); 80 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
66 81
67 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); 82 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) );
68 83
69 connect( devicesView, SIGNAL( clicked(QListViewItem*)), 84 connect( devicesView, SIGNAL( clicked(QListViewItem*)),
70 this, SLOT( startServiceActionClicked(QListViewItem*) ) ); 85 this, SLOT( startServiceActionClicked(QListViewItem*) ) );
71 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 86 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
72 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); 87 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) );
73 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), 88 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ),
74 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); 89 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) );
75 connect( m_localDevice, SIGNAL( available(const QString&,bool) ), 90 connect( m_localDevice, SIGNAL( available(const QString&,bool) ),
76 this, SLOT( deviceActive(const QString&,bool) ) ); 91 this, SLOT( deviceActive(const QString&,bool) ) );
77 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), 92 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ),
78 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); 93 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) );
79 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), 94 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ),
80 this, SLOT( addSignalStrength(const QString&,const QString&) ) ); 95 this, SLOT( addSignalStrength(const QString&,const QString&) ) );
96 connect(runButton, SIGNAL(clicked()), this, SLOT(doForward()));
81 97
82 // let hold be rightButtonClicked() 98 // let hold be rightButtonClicked()
83 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); 99 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold);
84 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); 100 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold);
85 101
86 //Load all icons needed 102 //Load all icons needed
87 m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); 103 m_offPix = Resource::loadPixmap( "opietooth/notconnected" );
88 m_onPix = Resource::loadPixmap( "opietooth/connected" ); 104 m_onPix = Resource::loadPixmap( "opietooth/connected" );
89 m_findPix = Resource::loadPixmap( "opietooth/find" ); 105 m_findPix = Resource::loadPixmap( "opietooth/find" );
90 106
91 QPalette pal = this->palette(); 107 QPalette pal = this->palette();
92 QColor col = pal.color( QPalette::Active, QColorGroup::Background ); 108 QColor col = pal.color( QPalette::Active, QColorGroup::Background );
@@ -99,24 +115,30 @@ BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
99 setCaption( tr( "Bluetooth Manager" ) ); 115 setCaption( tr( "Bluetooth Manager" ) );
100 116
101 readConfig(); 117 readConfig();
102 initGui(); 118 initGui();
103 119
104 devicesView->setRootIsDecorated(true); 120 devicesView->setRootIsDecorated(true);
105 m_iconLoader = new BTIconLoader(); 121 m_iconLoader = new BTIconLoader();
106 writeToHciConfig(); 122 writeToHciConfig();
107 addConnectedDevices(); 123 addConnectedDevices();
108 readSavedDevices(); 124 readSavedDevices();
109 addServicesToDevices(); 125 addServicesToDevices();
110 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); 126 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) );
127 forwarder = NULL;
128 serDevName->setText(tr("/dev/ircomm0"));
129 for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) {
130 serSpeed->insertItem(speeds[i].str);
131 }
132 serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1);
111} 133}
112 134
113/** 135/**
114 * Reads all options from the config file 136 * Reads all options from the config file
115 */ 137 */
116void BlueBase::readConfig() 138void BlueBase::readConfig()
117{ 139{
118 140
119 Config cfg( "bluetoothmanager" ); 141 Config cfg( "bluetoothmanager" );
120 cfg.setGroup( "bluezsettings" ); 142 cfg.setGroup( "bluezsettings" );
121 143
122 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with 144 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with
@@ -671,12 +693,51 @@ bool BlueBase::find( const RemoteDevice& rem )
671 for (; it.current(); ++it ) 693 for (; it.current(); ++it )
672 { 694 {
673 item = (BTListItem*) it.current(); 695 item = (BTListItem*) it.current();
674 if ( item->typeId() != BTListItem::Device ) 696 if ( item->typeId() != BTListItem::Device )
675 continue; 697 continue;
676 698
677 device = (BTDeviceItem*)item; 699 device = (BTDeviceItem*)item;
678 if ( rem.equals( device->remoteDevice() ) ) 700 if ( rem.equals( device->remoteDevice() ) )
679 return true; 701 return true;
680 } 702 }
681 return false; // not found 703 return false; // not found
682} 704}
705
706/**
707 * Start process of the cell phone forwarding
708 */
709void BlueBase::doForward()
710{
711 if (forwarder && forwarder->isRunning()) {
712 runButton->setText("start gateway");
713 forwarder->stop();
714 delete forwarder;
715 forwarder = NULL;
716 return;
717 }
718 QString str = serDevName->text();
719 forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val);
720 connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)),
721 this, SLOT(forwardExited(Opie::Core::OProcess*)));
722 if (forwarder->start(OProcess::NotifyOnExit) < 0) {
723 QMessageBox::critical(this, tr("Forwarder Error"),
724 tr("Forwarder start error:") + tr(strerror(errno)));
725 return;
726 }
727 runButton->setText("stop gateway");
728}
729
730/**
731 * React on the process end
732 */
733void BlueBase::forwardExit(Opie::Core::OProcess* proc)
734{
735 if (proc->exitStatus() != 0)
736 QMessageBox::critical(this, tr("Forwarder Error"),
737 tr("Forwarder start error"));
738 delete proc;
739 forwarder = NULL;
740 runButton->setText("start gateway");
741}
742
743//eof