summaryrefslogtreecommitdiff
path: root/noncore/net/opietooth/manager/bluebase.cpp
Unidiff
Diffstat (limited to 'noncore/net/opietooth/manager/bluebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 9ec5bf8..924d191 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -32,178 +32,189 @@
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <opie2/odebug.h> 33#include <opie2/odebug.h>
34using namespace Opie::Core; 34using namespace Opie::Core;
35 35
36/* QT */ 36/* QT */
37#include <qframe.h> 37#include <qframe.h>
38#include <qlabel.h> 38#include <qlabel.h>
39#include <qpushbutton.h> 39#include <qpushbutton.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qvariant.h> 41#include <qvariant.h>
42#include <qimage.h> 42#include <qimage.h>
43#include <qpixmap.h> 43#include <qpixmap.h>
44#include <qtabwidget.h> 44#include <qtabwidget.h>
45#include <qscrollview.h> 45#include <qscrollview.h>
46#include <qvbox.h> 46#include <qvbox.h>
47#include <qmessagebox.h> 47#include <qmessagebox.h>
48#include <qcombobox.h> 48#include <qcombobox.h>
49#include <qcheckbox.h> 49#include <qcheckbox.h>
50#include <qlineedit.h> 50#include <qlineedit.h>
51#include <qlistview.h> 51#include <qlistview.h>
52#include <qdir.h> 52#include <qdir.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54#include <qtimer.h> 54#include <qtimer.h>
55#include <qlist.h> 55#include <qlist.h>
56#include <qfile.h>
56 57
57/* STD */ 58/* STD */
58#include <remotedevice.h> 59#include <remotedevice.h>
59#include <services.h> 60#include <services.h>
60#include <stdlib.h> 61#include <stdlib.h>
61 62
62using namespace OpieTooth; 63using namespace OpieTooth;
63//Array of possible speeds of the serial port 64//Array of possible speeds of the serial port
64struct SerSpeed { 65struct SerSpeed {
65 const char* str; //string value 66 const char* str; //string value
66 int val; //value itself 67 int val; //value itself
67} speeds[] = { 68} speeds[] = {
68 { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, 69 { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 },
69 { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, 70 { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 },
70 { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, 71 { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 },
71 { "115200", B115200} 72 { "115200", B115200}
72}; 73};
73 74
74BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 75BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
75 : BluetoothBase( parent, name, fl ) 76 : BluetoothBase( parent, name, fl )
76{ 77{
77 m_localDevice = new Manager( "hci0" ); 78 m_localDevice = new Manager( "hci0" );
78 79
79 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); 80 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
80 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); 81 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
81 82
82 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); 83 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) );
83 84
84 connect( devicesView, SIGNAL( clicked(QListViewItem*)), 85 connect( devicesView, SIGNAL( clicked(QListViewItem*)),
85 this, SLOT( startServiceActionClicked(QListViewItem*) ) ); 86 this, SLOT( startServiceActionClicked(QListViewItem*) ) );
86 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 87 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
87 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); 88 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) );
88 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), 89 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ),
89 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); 90 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) );
90 connect( m_localDevice, SIGNAL( available(const QString&,bool) ), 91 connect( m_localDevice, SIGNAL( available(const QString&,bool) ),
91 this, SLOT( deviceActive(const QString&,bool) ) ); 92 this, SLOT( deviceActive(const QString&,bool) ) );
92 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), 93 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ),
93 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); 94 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) );
94 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), 95 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ),
95 this, SLOT( addSignalStrength(const QString&,const QString&) ) ); 96 this, SLOT( addSignalStrength(const QString&,const QString&) ) );
96 connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); 97 connect(runButton, SIGNAL(clicked()), this, SLOT(doForward()));
98 connect(encCheckBox, SIGNAL(toggled(bool)), this, SLOT(doEncrypt(bool)));
97 99
98 // let hold be rightButtonClicked() 100 // let hold be rightButtonClicked()
99 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); 101 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold);
100 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); 102 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold);
101 103
102 //Load all icons needed 104 //Load all icons needed
103 m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); 105 m_offPix = Resource::loadPixmap( "opietooth/notconnected" );
104 m_onPix = Resource::loadPixmap( "opietooth/connected" ); 106 m_onPix = Resource::loadPixmap( "opietooth/connected" );
105 m_findPix = Resource::loadPixmap( "opietooth/find" ); 107 m_findPix = Resource::loadPixmap( "opietooth/find" );
106 108
107 QPalette pal = this->palette(); 109 QPalette pal = this->palette();
108 QColor col = pal.color( QPalette::Active, QColorGroup::Background ); 110 QColor col = pal.color( QPalette::Active, QColorGroup::Background );
109 pal.setColor( QPalette::Active, QColorGroup::Button, col ); 111 pal.setColor( QPalette::Active, QColorGroup::Button, col );
110 pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); 112 pal.setColor( QPalette::Inactive, QColorGroup::Button, col );
111 pal.setColor( QPalette::Normal, QColorGroup::Button, col ); 113 pal.setColor( QPalette::Normal, QColorGroup::Button, col );
112 pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); 114 pal.setColor( QPalette::Disabled, QColorGroup::Button, col );
113 this->setPalette( pal ); 115 this->setPalette( pal );
114 116
115 setCaption( tr( "Bluetooth Manager" ) ); 117 setCaption( tr( "Bluetooth Manager" ) );
116 118
117 readConfig(); 119 readConfig();
118 initGui(); 120 initGui();
119 121
120 devicesView->setRootIsDecorated(true); 122 devicesView->setRootIsDecorated(true);
121 m_iconLoader = new BTIconLoader(); 123 m_iconLoader = new BTIconLoader();
122 writeToHciConfig(); 124 writeToHciConfig();
123 addConnectedDevices(); 125 addConnectedDevices();
124 readSavedDevices(); 126 readSavedDevices();
125 addServicesToDevices(); 127 addServicesToDevices();
126 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); 128 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) );
127 forwarder = NULL; 129 forwarder = NULL;
128 serDevName->setText(tr("/dev/ircomm0")); 130 serDevName->setText(tr("/dev/ircomm0"));
129 for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) { 131 for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) {
130 serSpeed->insertItem(speeds[i].str); 132 serSpeed->insertItem(speeds[i].str);
131 } 133 }
132 serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1); 134 serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1);
135 encCheckBox->setChecked(true);
133} 136}
134 137
135/** 138/**
136 * Reads all options from the config file 139 * Reads all options from the config file
137 */ 140 */
138void BlueBase::readConfig() 141void BlueBase::readConfig()
139{ 142{
140 143
141 Config cfg( "bluetoothmanager" ); 144 Config cfg( "bluetoothmanager" );
142 cfg.setGroup( "bluezsettings" ); 145 cfg.setGroup( "bluezsettings" );
143 146
144 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with 147 m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with
145 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak 148 m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak
146 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); 149 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE );
147 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); 150 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE );
148 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); 151 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE );
149 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); 152 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE );
150} 153}
151 154
152/** 155/**
153 * Writes all options to the config file 156 * Writes all options to the config file
154 */ 157 */
155void BlueBase::writeConfig() 158void BlueBase::writeConfig()
156{ 159{
157 160
158 Config cfg( "bluetoothmanager" ); 161 Config cfg( "bluetoothmanager" );
159 cfg.setGroup( "bluezsettings" ); 162 cfg.setGroup( "bluezsettings" );
160 163
161 cfg.writeEntry( "name" , m_deviceName ); 164 cfg.writeEntry( "name" , m_deviceName );
162 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); 165 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey );
163 cfg.writeEntry( "useEncryption" , m_useEncryption ); 166 cfg.writeEntry( "useEncryption" , m_useEncryption );
164 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); 167 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification );
165 cfg.writeEntry( "enablePagescan" , m_enablePagescan ); 168 cfg.writeEntry( "enablePagescan" , m_enablePagescan );
166 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); 169 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
167 170
168 writeToHciConfig(); 171 writeToHciConfig();
169} 172}
170 173
171/** 174/**
172 * Modify the hcid.conf file to our needs 175 * Modify the hcid.conf file to our needs
173 */ 176 */
174void BlueBase::writeToHciConfig() 177void BlueBase::writeToHciConfig()
175{ 178{
179 QFile pinFile("/etc/bluetooth/pin"); // /etc/bluetooth/pin file
176 owarn << "writeToHciConfig" << oendl; 180 owarn << "writeToHciConfig" << oendl;
181 //Write /etc/bluetooth/hcid.conf file
177 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); 182 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
178 hciconf.load(); 183 hciconf.load();
179 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" ); 184 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" );
180 hciconf.setName( m_deviceName ); 185 hciconf.setName( m_deviceName );
181 hciconf.setEncrypt( m_useEncryption ); 186 hciconf.setEncrypt( m_useEncryption );
182 hciconf.setAuth( m_enableAuthentification ); 187 hciconf.setAuth( m_enableAuthentification );
183 hciconf.setPscan( m_enablePagescan ); 188 hciconf.setPscan( m_enablePagescan );
184 hciconf.setIscan( m_enableInquiryscan ); 189 hciconf.setIscan( m_enableInquiryscan );
185 hciconf.save(); 190 hciconf.save();
191 // Write /etc/bluetooth/pin (default PIN file)
192 pinFile.open(IO_WriteOnly | IO_Truncate);
193 pinFile.writeBlock(m_defaultPasskey, m_defaultPasskey.length());
194 pinFile.writeBlock("\n", sizeof("\n"));
195 pinFile.flush();
196 pinFile.close();
186} 197}
187 198
188 199
189/** 200/**
190 * Read the list of already known devices 201 * Read the list of already known devices
191 */ 202 */
192void BlueBase::readSavedDevices() 203void BlueBase::readSavedDevices()
193{ 204{
194 205
195 QValueList<RemoteDevice> loadedDevices; 206 QValueList<RemoteDevice> loadedDevices;
196 DeviceHandler handler; 207 DeviceHandler handler;
197 loadedDevices = handler.load(); 208 loadedDevices = handler.load();
198 209
199 addSearchedDevices( loadedDevices ); 210 addSearchedDevices( loadedDevices );
200} 211}
201 212
202 213
203/** 214/**
204 * Write the list of already known devices 215 * Write the list of already known devices
205 */ 216 */
206void BlueBase::writeSavedDevices() 217void BlueBase::writeSavedDevices()
207{ 218{
208 QListViewItemIterator it( devicesView ); 219 QListViewItemIterator it( devicesView );
209 BTListItem* item; 220 BTListItem* item;
@@ -719,25 +730,34 @@ void BlueBase::doForward()
719 forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); 730 forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val);
720 connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)), 731 connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)),
721 this, SLOT(forwardExited(Opie::Core::OProcess*))); 732 this, SLOT(forwardExited(Opie::Core::OProcess*)));
722 if (forwarder->start(OProcess::NotifyOnExit) < 0) { 733 if (forwarder->start(OProcess::NotifyOnExit) < 0) {
723 QMessageBox::critical(this, tr("Forwarder Error"), 734 QMessageBox::critical(this, tr("Forwarder Error"),
724 tr("Forwarder start error:") + tr(strerror(errno))); 735 tr("Forwarder start error:") + tr(strerror(errno)));
725 return; 736 return;
726 } 737 }
727 runButton->setText("stop gateway"); 738 runButton->setText("stop gateway");
728} 739}
729 740
730/** 741/**
731 * React on the process end 742 * React on the process end
732 */ 743 */
733void BlueBase::forwardExit(Opie::Core::OProcess* proc) 744void BlueBase::forwardExit(Opie::Core::OProcess* proc)
734{ 745{
735 if (proc->exitStatus() != 0) 746 if (proc->exitStatus() != 0)
736 QMessageBox::critical(this, tr("Forwarder Error"), 747 QMessageBox::critical(this, tr("Forwarder Error"),
737 tr("Forwarder start error")); 748 tr("Forwarder start error"));
738 delete proc; 749 delete proc;
739 forwarder = NULL; 750 forwarder = NULL;
740 runButton->setText("start gateway"); 751 runButton->setText("start gateway");
741} 752}
742 753
754/**
755 * Encrypt entered passkey
756 * doit - do encryption of the key
757 */
758void BlueBase::doEncrypt(bool doit)
759{
760 passkeyLine->setEchoMode((doit)? QLineEdit::Password: QLineEdit::Normal);
761}
762
743//eof 763//eof