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 | |||
@@ -1,134 +1,156 @@ | |||
1 | /* | 1 | /* |
2 | * bluebase.cpp * | 2 | * bluebase.cpp * |
3 | * --------------------- | 3 | * --------------------- |
4 | * | 4 | * |
5 | * copyright : (c) 2002 by Maximilian Reiß | 5 | * copyright : (c) 2002 by Maximilian Reiß |
6 | * email : max.reiss@gmx.de | 6 | * email : max.reiss@gmx.de |
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | /*************************************************************************** | 9 | /*************************************************************************** |
10 | * * | 10 | * * |
11 | * This program is free software; you can redistribute it and/or modify * | 11 | * This program is free software; you can redistribute it and/or modify * |
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> |
30 | using namespace Opie::Core; | 34 | using 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 | ||
57 | using namespace OpieTooth; | 62 | using namespace OpieTooth; |
63 | //Array of possible speeds of the serial port | ||
64 | struct 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 | ||
59 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 74 | BlueBase::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 ); |
93 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 109 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
94 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 110 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
95 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 111 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
96 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 112 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
97 | this->setPalette( pal ); | 113 | this->setPalette( pal ); |
98 | 114 | ||
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 | */ |
116 | void BlueBase::readConfig() | 138 | void 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 |
123 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 145 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
124 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); | 146 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
125 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); | 147 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
126 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); | 148 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
127 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); | 149 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
128 | } | 150 | } |
129 | 151 | ||
130 | /** | 152 | /** |
131 | * Writes all options to the config file | 153 | * Writes all options to the config file |
132 | */ | 154 | */ |
133 | void BlueBase::writeConfig() | 155 | void BlueBase::writeConfig() |
134 | { | 156 | { |
@@ -659,24 +681,63 @@ BlueBase::~BlueBase() | |||
659 | 681 | ||
660 | /** | 682 | /** |
661 | * find searches the ListView for a BTDeviceItem containig | 683 | * find searches the ListView for a BTDeviceItem containig |
662 | * the same Device if found return true else false | 684 | * the same Device if found return true else false |
663 | * @param dev RemoteDevice to find | 685 | * @param dev RemoteDevice to find |
664 | * @return returns true if found | 686 | * @return returns true if found |
665 | */ | 687 | */ |
666 | bool BlueBase::find( const RemoteDevice& rem ) | 688 | bool BlueBase::find( const RemoteDevice& rem ) |
667 | { | 689 | { |
668 | QListViewItemIterator it( devicesView ); | 690 | QListViewItemIterator it( devicesView ); |
669 | BTListItem* item; | 691 | BTListItem* item; |
670 | BTDeviceItem* device; | 692 | BTDeviceItem* device; |
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 | */ | ||
709 | void 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 | */ | ||
733 | void 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 | ||