-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 13954c5..58f97fa 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,226 +1,230 @@ | |||
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" | 24 | #include "forwarder.h" |
25 | #include "servicesdialog.h" | 25 | #include "servicesdialog.h" |
26 | #include <termios.h> | 26 | #include <termios.h> |
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <errno.h> | 28 | #include <errno.h> |
29 | 29 | ||
30 | /* OPIE */ | 30 | /* OPIE */ |
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #include <qpe/resource.h> | 32 | #include <qpe/resource.h> |
33 | #include <qpe/config.h> | 33 | #include <qpe/config.h> |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #ifdef Q_WS_QWS | ||
36 | #include <qpe/qcopenvelope_qws.h> | ||
37 | #endif | ||
38 | |||
35 | using namespace Opie::Core; | 39 | using namespace Opie::Core; |
36 | 40 | ||
37 | /* QT */ | 41 | /* QT */ |
38 | #include <qframe.h> | 42 | #include <qframe.h> |
39 | #include <qlabel.h> | 43 | #include <qlabel.h> |
40 | #include <qpushbutton.h> | 44 | #include <qpushbutton.h> |
41 | #include <qlayout.h> | 45 | #include <qlayout.h> |
42 | #include <qvariant.h> | 46 | #include <qvariant.h> |
43 | #include <qimage.h> | 47 | #include <qimage.h> |
44 | #include <qpixmap.h> | 48 | #include <qpixmap.h> |
45 | #include <qtabwidget.h> | 49 | #include <qtabwidget.h> |
46 | #include <qscrollview.h> | 50 | #include <qscrollview.h> |
47 | #include <qvbox.h> | 51 | #include <qvbox.h> |
48 | #include <qmessagebox.h> | 52 | #include <qmessagebox.h> |
49 | #include <qcombobox.h> | 53 | #include <qcombobox.h> |
50 | #include <qcheckbox.h> | 54 | #include <qcheckbox.h> |
51 | #include <qlineedit.h> | 55 | #include <qlineedit.h> |
52 | #include <qlistview.h> | 56 | #include <qlistview.h> |
53 | #include <qdir.h> | 57 | #include <qdir.h> |
54 | #include <qpopupmenu.h> | 58 | #include <qpopupmenu.h> |
55 | #include <qtimer.h> | 59 | #include <qtimer.h> |
56 | #include <qlist.h> | 60 | #include <qlist.h> |
57 | #include <qfile.h> | 61 | #include <qfile.h> |
58 | 62 | ||
59 | /* STD */ | 63 | /* STD */ |
60 | #include <remotedevice.h> | 64 | #include <remotedevice.h> |
61 | #include <services.h> | 65 | #include <services.h> |
62 | #include <stdlib.h> | 66 | #include <stdlib.h> |
63 | 67 | ||
64 | using namespace OpieTooth; | 68 | using namespace OpieTooth; |
65 | //Array of possible speeds of the serial port | 69 | //Array of possible speeds of the serial port |
66 | struct SerSpeed { | 70 | struct SerSpeed { |
67 | const char* str; //string value | 71 | const char* str; //string value |
68 | int val; //value itself | 72 | int val; //value itself |
69 | } speeds[] = { | 73 | } speeds[] = { |
70 | { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, | 74 | { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, |
71 | { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, | 75 | { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, |
72 | { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, | 76 | { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, |
73 | { "115200", B115200} | 77 | { "115200", B115200} |
74 | }; | 78 | }; |
75 | 79 | ||
76 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 80 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
77 | : BluetoothBase( parent, name, fl ) | 81 | : BluetoothBase( parent, name, fl ) |
78 | { | 82 | { |
79 | m_localDevice = new Manager( "hci0" ); | 83 | m_localDevice = new Manager( "hci0" ); |
80 | 84 | ||
81 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 85 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
82 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 86 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
83 | 87 | ||
84 | connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); | 88 | connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); |
85 | 89 | ||
86 | connect( devicesView, SIGNAL( clicked(QListViewItem*)), | 90 | connect( devicesView, SIGNAL( clicked(QListViewItem*)), |
87 | this, SLOT( startServiceActionClicked(QListViewItem*) ) ); | 91 | this, SLOT( startServiceActionClicked(QListViewItem*) ) ); |
88 | connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), | 92 | connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), |
89 | this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); | 93 | this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); |
90 | connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), | 94 | connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), |
91 | this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); | 95 | this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); |
92 | connect( m_localDevice, SIGNAL( available(const QString&,bool) ), | 96 | connect( m_localDevice, SIGNAL( available(const QString&,bool) ), |
93 | this, SLOT( deviceActive(const QString&,bool) ) ); | 97 | this, SLOT( deviceActive(const QString&,bool) ) ); |
94 | connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), | 98 | connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), |
95 | this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); | 99 | this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); |
96 | connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), | 100 | connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), |
97 | this, SLOT( addSignalStrength(const QString&,const QString&) ) ); | 101 | this, SLOT( addSignalStrength(const QString&,const QString&) ) ); |
98 | connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); | 102 | connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); |
99 | connect(encCheckBox, SIGNAL(toggled(bool)), this, SLOT(doEncrypt(bool))); | 103 | connect(encCheckBox, SIGNAL(toggled(bool)), this, SLOT(doEncrypt(bool))); |
100 | connect(servicesEditButton, SIGNAL(clicked()), this, SLOT(editServices())); | 104 | connect(servicesEditButton, SIGNAL(clicked()), this, SLOT(editServices())); |
101 | 105 | ||
102 | // let hold be rightButtonClicked() | 106 | // let hold be rightButtonClicked() |
103 | QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); | 107 | QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); |
104 | QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); | 108 | QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); |
105 | 109 | ||
106 | //Load all icons needed | 110 | //Load all icons needed |
107 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); | 111 | m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); |
108 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); | 112 | m_onPix = Resource::loadPixmap( "opietooth/connected" ); |
109 | m_findPix = Resource::loadPixmap( "opietooth/find" ); | 113 | m_findPix = Resource::loadPixmap( "opietooth/find" ); |
110 | 114 | ||
111 | QPalette pal = this->palette(); | 115 | QPalette pal = this->palette(); |
112 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 116 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
113 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 117 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
114 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 118 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
115 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 119 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
116 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 120 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
117 | this->setPalette( pal ); | 121 | this->setPalette( pal ); |
118 | 122 | ||
119 | setCaption( tr( "Bluetooth Manager" ) ); | 123 | setCaption( tr( "Bluetooth Manager" ) ); |
120 | 124 | ||
121 | readConfig(); | 125 | readConfig(); |
122 | initGui(); | 126 | initGui(); |
123 | 127 | ||
124 | devicesView->setRootIsDecorated(true); | 128 | devicesView->setRootIsDecorated(true); |
125 | m_iconLoader = new BTIconLoader(); | 129 | m_iconLoader = new BTIconLoader(); |
126 | writeToHciConfig(); | 130 | writeToHciConfig(); |
127 | addConnectedDevices(); | 131 | addConnectedDevices(); |
128 | readSavedDevices(); | 132 | readSavedDevices(); |
129 | addServicesToDevices(); | 133 | addServicesToDevices(); |
130 | QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); | 134 | QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); |
131 | forwarder = NULL; | 135 | forwarder = NULL; |
132 | } | 136 | } |
133 | 137 | ||
134 | /** | 138 | /** |
135 | * Reads all options from the config file | 139 | * Reads all options from the config file |
136 | */ | 140 | */ |
137 | void BlueBase::readConfig() | 141 | void BlueBase::readConfig() |
138 | { | 142 | { |
139 | 143 | ||
140 | Config cfg( "bluetoothmanager" ); | 144 | Config cfg( "bluetoothmanager" ); |
141 | cfg.setGroup( "bluezsettings" ); | 145 | cfg.setGroup( "bluezsettings" ); |
142 | 146 | ||
143 | 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 |
144 | 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 |
145 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); | 149 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
146 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); | 150 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
147 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); | 151 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
148 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); | 152 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
149 | } | 153 | } |
150 | 154 | ||
151 | /** | 155 | /** |
152 | * Writes all options to the config file | 156 | * Writes all options to the config file |
153 | */ | 157 | */ |
154 | void BlueBase::writeConfig() | 158 | void BlueBase::writeConfig() |
155 | { | 159 | { |
156 | 160 | ||
157 | Config cfg( "bluetoothmanager" ); | 161 | Config cfg( "bluetoothmanager" ); |
158 | cfg.setGroup( "bluezsettings" ); | 162 | cfg.setGroup( "bluezsettings" ); |
159 | 163 | ||
160 | cfg.writeEntry( "name" , m_deviceName ); | 164 | cfg.writeEntry( "name" , m_deviceName ); |
161 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); | 165 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); |
162 | cfg.writeEntry( "useEncryption" , m_useEncryption ); | 166 | cfg.writeEntry( "useEncryption" , m_useEncryption ); |
163 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); | 167 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); |
164 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); | 168 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); |
165 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); | 169 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); |
166 | 170 | ||
167 | writeToHciConfig(); | 171 | writeToHciConfig(); |
168 | } | 172 | } |
169 | 173 | ||
170 | /** | 174 | /** |
171 | * Modify the hcid.conf file to our needs | 175 | * Modify the hcid.conf file to our needs |
172 | */ | 176 | */ |
173 | void BlueBase::writeToHciConfig() | 177 | void BlueBase::writeToHciConfig() |
174 | { | 178 | { |
175 | QFile pinFile("/etc/bluetooth/pin"); // /etc/bluetooth/pin file | 179 | QFile pinFile("/etc/bluetooth/pin"); // /etc/bluetooth/pin file |
176 | owarn << "writeToHciConfig" << oendl; | 180 | owarn << "writeToHciConfig" << oendl; |
177 | //Write /etc/bluetooth/hcid.conf file | 181 | //Write /etc/bluetooth/hcid.conf file |
178 | HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); | 182 | HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); |
179 | hciconf.load(); | 183 | hciconf.load(); |
180 | hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" ); | 184 | hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" ); |
181 | hciconf.setName( m_deviceName ); | 185 | hciconf.setName( m_deviceName ); |
182 | hciconf.setEncrypt( m_useEncryption ); | 186 | hciconf.setEncrypt( m_useEncryption ); |
183 | hciconf.setAuth( m_enableAuthentification ); | 187 | hciconf.setAuth( m_enableAuthentification ); |
184 | hciconf.setPscan( m_enablePagescan ); | 188 | hciconf.setPscan( m_enablePagescan ); |
185 | hciconf.setIscan( m_enableInquiryscan ); | 189 | hciconf.setIscan( m_enableInquiryscan ); |
186 | hciconf.save(); | 190 | hciconf.save(); |
187 | // Write /etc/bluetooth/pin (default PIN file) | 191 | // Write /etc/bluetooth/pin (default PIN file) |
188 | pinFile.open(IO_WriteOnly | IO_Truncate); | 192 | pinFile.open(IO_WriteOnly | IO_Truncate); |
189 | pinFile.writeBlock(m_defaultPasskey, m_defaultPasskey.length()); | 193 | pinFile.writeBlock(m_defaultPasskey, m_defaultPasskey.length()); |
190 | pinFile.writeBlock("\n", sizeof("\n")); | 194 | pinFile.writeBlock("\n", sizeof("\n")); |
191 | pinFile.flush(); | 195 | pinFile.flush(); |
192 | pinFile.close(); | 196 | pinFile.close(); |
193 | } | 197 | } |
194 | 198 | ||
195 | 199 | ||
196 | /** | 200 | /** |
197 | * Read the list of already known devices | 201 | * Read the list of already known devices |
198 | */ | 202 | */ |
199 | void BlueBase::readSavedDevices() | 203 | void BlueBase::readSavedDevices() |
200 | { | 204 | { |
201 | 205 | ||
202 | QValueList<RemoteDevice> loadedDevices; | 206 | QValueList<RemoteDevice> loadedDevices; |
203 | DeviceHandler handler; | 207 | DeviceHandler handler; |
204 | loadedDevices = handler.load(); | 208 | loadedDevices = handler.load(); |
205 | 209 | ||
206 | addSearchedDevices( loadedDevices ); | 210 | addSearchedDevices( loadedDevices ); |
207 | } | 211 | } |
208 | 212 | ||
209 | 213 | ||
210 | /** | 214 | /** |
211 | * Write the list of already known devices | 215 | * Write the list of already known devices |
212 | */ | 216 | */ |
213 | void BlueBase::writeSavedDevices() | 217 | void BlueBase::writeSavedDevices() |
214 | { | 218 | { |
215 | QListViewItemIterator it( devicesView ); | 219 | QListViewItemIterator it( devicesView ); |
216 | BTListItem* item; | 220 | BTListItem* item; |
217 | BTDeviceItem* device; | 221 | BTDeviceItem* device; |
218 | RemoteDevice::ValueList list; | 222 | RemoteDevice::ValueList list; |
219 | for ( ; it.current(); ++it ) | 223 | for ( ; it.current(); ++it ) |
220 | { | 224 | { |
221 | item = (BTListItem*)it.current(); | 225 | item = (BTListItem*)it.current(); |
222 | if(item->typeId() != BTListItem::Device ) | 226 | if(item->typeId() != BTListItem::Device ) |
223 | continue; | 227 | continue; |
224 | device = (BTDeviceItem*)item; | 228 | device = (BTDeviceItem*)item; |
225 | 229 | ||
226 | list.append( device->remoteDevice() ); | 230 | list.append( device->remoteDevice() ); |
@@ -499,283 +503,299 @@ void BlueBase::addServicesToDevice( const QString& device, Services::ValueList s | |||
499 | } | 503 | } |
500 | 504 | ||
501 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); | 505 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); |
502 | } | 506 | } |
503 | } | 507 | } |
504 | else | 508 | else |
505 | { | 509 | { |
506 | Services s1; | 510 | Services s1; |
507 | s1.setServiceName( tr("no services found") ); | 511 | s1.setServiceName( tr("no services found") ); |
508 | serviceItem = new BTServiceItem( deviceItem, s1 ); | 512 | serviceItem = new BTServiceItem( deviceItem, s1 ); |
509 | } | 513 | } |
510 | // now remove them from the list | 514 | // now remove them from the list |
511 | m_deviceList.remove( it ); | 515 | m_deviceList.remove( it ); |
512 | } | 516 | } |
513 | 517 | ||
514 | void BlueBase::addSignalStrength() | 518 | void BlueBase::addSignalStrength() |
515 | { | 519 | { |
516 | 520 | ||
517 | QListViewItemIterator it( connectionsView ); | 521 | QListViewItemIterator it( connectionsView ); |
518 | for ( ; it.current(); ++it ) | 522 | for ( ; it.current(); ++it ) |
519 | { | 523 | { |
520 | m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); | 524 | m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); |
521 | } | 525 | } |
522 | 526 | ||
523 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); | 527 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); |
524 | } | 528 | } |
525 | 529 | ||
526 | void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) | 530 | void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) |
527 | { | 531 | { |
528 | 532 | ||
529 | QListViewItemIterator it( connectionsView ); | 533 | QListViewItemIterator it( connectionsView ); |
530 | for ( ; it.current(); ++it ) | 534 | for ( ; it.current(); ++it ) |
531 | { | 535 | { |
532 | if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) | 536 | if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) |
533 | { | 537 | { |
534 | ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); | 538 | ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); |
535 | } | 539 | } |
536 | } | 540 | } |
537 | } | 541 | } |
538 | 542 | ||
539 | /** | 543 | /** |
540 | * Add the existing connections (pairs) to the connections tab. | 544 | * Add the existing connections (pairs) to the connections tab. |
541 | * This one triggers the search | 545 | * This one triggers the search |
542 | */ | 546 | */ |
543 | void BlueBase::addConnectedDevices() | 547 | void BlueBase::addConnectedDevices() |
544 | { | 548 | { |
545 | m_localDevice->searchConnections(); | 549 | m_localDevice->searchConnections(); |
546 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); | 550 | QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); |
547 | } | 551 | } |
548 | 552 | ||
549 | /** | 553 | /** |
550 | * This adds the found connections to the connection tab. | 554 | * This adds the found connections to the connection tab. |
551 | * @param connectionList the ValueList with all current connections | 555 | * @param connectionList the ValueList with all current connections |
552 | */ | 556 | */ |
553 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) | 557 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) |
554 | { | 558 | { |
555 | 559 | ||
556 | QValueList<OpieTooth::ConnectionState>::Iterator it; | 560 | QValueList<OpieTooth::ConnectionState>::Iterator it; |
557 | BTConnectionItem * connectionItem; | 561 | BTConnectionItem * connectionItem; |
558 | 562 | ||
559 | if ( !connectionList.isEmpty() ) | 563 | if ( !connectionList.isEmpty() ) |
560 | { | 564 | { |
561 | 565 | ||
562 | for (it = connectionList.begin(); it != connectionList.end(); ++it) | 566 | for (it = connectionList.begin(); it != connectionList.end(); ++it) |
563 | { | 567 | { |
564 | 568 | ||
565 | QListViewItemIterator it2( connectionsView ); | 569 | QListViewItemIterator it2( connectionsView ); |
566 | bool found = false; | 570 | bool found = false; |
567 | for ( ; it2.current(); ++it2 ) | 571 | for ( ; it2.current(); ++it2 ) |
568 | { | 572 | { |
569 | if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) | 573 | if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) |
570 | { | 574 | { |
571 | found = true; | 575 | found = true; |
572 | } | 576 | } |
573 | } | 577 | } |
574 | 578 | ||
575 | if ( found == false ) | 579 | if ( found == false ) |
576 | { | 580 | { |
577 | connectionItem = new BTConnectionItem( connectionsView, (*it) ); | 581 | connectionItem = new BTConnectionItem( connectionsView, (*it) ); |
578 | 582 | ||
579 | if( m_deviceList.find((*it).mac()).data() ) | 583 | if( m_deviceList.find((*it).mac()).data() ) |
580 | { | 584 | { |
581 | connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); | 585 | connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); |
582 | } | 586 | } |
583 | } | 587 | } |
584 | 588 | ||
585 | } | 589 | } |
586 | 590 | ||
587 | QListViewItemIterator it2( connectionsView ); | 591 | QListViewItemIterator it2( connectionsView ); |
588 | for ( ; it2.current(); ++it2 ) | 592 | for ( ; it2.current(); ++it2 ) |
589 | { | 593 | { |
590 | bool found = false; | 594 | bool found = false; |
591 | for (it = connectionList.begin(); it != connectionList.end(); ++it) | 595 | for (it = connectionList.begin(); it != connectionList.end(); ++it) |
592 | { | 596 | { |
593 | if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) | 597 | if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) |
594 | { | 598 | { |
595 | found = true; | 599 | found = true; |
596 | } | 600 | } |
597 | } | 601 | } |
598 | 602 | ||
599 | if ( !found ) | 603 | if ( !found ) |
600 | { | 604 | { |
601 | delete it2.current(); | 605 | delete it2.current(); |
602 | } | 606 | } |
603 | 607 | ||
604 | } | 608 | } |
605 | 609 | ||
606 | 610 | ||
607 | } | 611 | } |
608 | else | 612 | else |
609 | { | 613 | { |
610 | connectionsView->clear(); | 614 | connectionsView->clear(); |
611 | ConnectionState con; | 615 | ConnectionState con; |
612 | con.setMac( tr("No connections found") ); | 616 | con.setMac( tr("No connections found") ); |
613 | connectionItem = new BTConnectionItem( connectionsView , con ); | 617 | connectionItem = new BTConnectionItem( connectionsView , con ); |
614 | } | 618 | } |
615 | 619 | ||
616 | // recall connection search after some time | 620 | // recall connection search after some time |
617 | QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); | 621 | QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); |
618 | } | 622 | } |
619 | 623 | ||
620 | 624 | ||
621 | /** | 625 | /** |
622 | * Find out if a device can currently be reached | 626 | * Find out if a device can currently be reached |
623 | * @param device | 627 | * @param device |
624 | */ | 628 | */ |
625 | void BlueBase::deviceActive( const RemoteDevice &device ) | 629 | void BlueBase::deviceActive( const RemoteDevice &device ) |
626 | { | 630 | { |
627 | // search by mac, async, gets a signal back | 631 | // search by mac, async, gets a signal back |
628 | // We should have a BTDeviceItem there or where does it get added to the map -zecke | 632 | // We should have a BTDeviceItem there or where does it get added to the map -zecke |
629 | m_localDevice->isAvailable( device.mac() ); | 633 | m_localDevice->isAvailable( device.mac() ); |
630 | } | 634 | } |
631 | 635 | ||
632 | 636 | ||
633 | /** | 637 | /** |
634 | * The signal catcher. Set the avail. status on device. | 638 | * The signal catcher. Set the avail. status on device. |
635 | * @param device - the mac address | 639 | * @param device - the mac address |
636 | * @param connected - if it is avail. or not | 640 | * @param connected - if it is avail. or not |
637 | */ | 641 | */ |
638 | void BlueBase::deviceActive( const QString& device, bool connected ) | 642 | void BlueBase::deviceActive( const QString& device, bool connected ) |
639 | { | 643 | { |
640 | odebug << "deviceActive slot" << oendl; | 644 | odebug << "deviceActive slot" << oendl; |
641 | 645 | ||
642 | QMap<QString,BTDeviceItem*>::Iterator it; | 646 | QMap<QString,BTDeviceItem*>::Iterator it; |
643 | 647 | ||
644 | it = m_deviceList.find( device ); | 648 | it = m_deviceList.find( device ); |
645 | if( it == m_deviceList.end() ) | 649 | if( it == m_deviceList.end() ) |
646 | return; | 650 | return; |
647 | 651 | ||
648 | BTDeviceItem* deviceItem = it.data(); | 652 | BTDeviceItem* deviceItem = it.data(); |
649 | 653 | ||
650 | if ( connected ) | 654 | if ( connected ) |
651 | { | 655 | { |
652 | deviceItem->setPixmap( 1, m_onPix ); | 656 | deviceItem->setPixmap( 1, m_onPix ); |
653 | } | 657 | } |
654 | else | 658 | else |
655 | { | 659 | { |
656 | deviceItem->setPixmap( 1, m_offPix ); | 660 | deviceItem->setPixmap( 1, m_offPix ); |
657 | } | 661 | } |
658 | m_deviceList.remove( it ); | 662 | m_deviceList.remove( it ); |
659 | } | 663 | } |
660 | 664 | ||
661 | 665 | ||
662 | /** | 666 | /** |
663 | * Open the "scan for devices" dialog | 667 | * Open the "scan for devices" dialog |
664 | */ | 668 | */ |
665 | void BlueBase::startScan() | 669 | void BlueBase::startScan() |
666 | { | 670 | { |
667 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", | 671 | ScanDialog *scan = new ScanDialog( this, "ScanDialog", |
668 | true, WDestructiveClose ); | 672 | true, WDestructiveClose ); |
669 | QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ), | 673 | QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ), |
670 | this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) ); | 674 | this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) ); |
671 | 675 | ||
672 | QPEApplication::showDialog( scan ); | 676 | QPEApplication::showDialog( scan ); |
673 | } | 677 | } |
674 | 678 | ||
675 | 679 | ||
676 | /** | 680 | /** |
677 | * Set the informations about the local device in information Tab | 681 | * Set the informations about the local device in information Tab |
678 | */ | 682 | */ |
679 | void BlueBase::setInfo() | 683 | void BlueBase::setInfo() |
680 | { | 684 | { |
681 | StatusLabel->setText( status() ); | 685 | StatusLabel->setText( status() ); |
682 | } | 686 | } |
683 | 687 | ||
684 | 688 | ||
685 | /** | 689 | /** |
686 | * Decontructor | 690 | * Decontructor |
687 | */ | 691 | */ |
688 | BlueBase::~BlueBase() | 692 | BlueBase::~BlueBase() |
689 | { | 693 | { |
690 | writeSavedDevices(); | 694 | writeSavedDevices(); |
695 | if (forwarder) { | ||
696 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
697 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | ||
698 | << QPEApplication::Enable; | ||
699 | #endif | ||
700 | delete forwarder; | ||
701 | forwarder = NULL; | ||
702 | } | ||
691 | delete m_iconLoader; | 703 | delete m_iconLoader; |
692 | } | 704 | } |
693 | 705 | ||
694 | 706 | ||
695 | /** | 707 | /** |
696 | * find searches the ListView for a BTDeviceItem containig | 708 | * find searches the ListView for a BTDeviceItem containig |
697 | * the same Device if found return true else false | 709 | * the same Device if found return true else false |
698 | * @param dev RemoteDevice to find | 710 | * @param dev RemoteDevice to find |
699 | * @return returns true if found | 711 | * @return returns true if found |
700 | */ | 712 | */ |
701 | bool BlueBase::find( const RemoteDevice& rem ) | 713 | bool BlueBase::find( const RemoteDevice& rem ) |
702 | { | 714 | { |
703 | QListViewItemIterator it( devicesView ); | 715 | QListViewItemIterator it( devicesView ); |
704 | BTListItem* item; | 716 | BTListItem* item; |
705 | BTDeviceItem* device; | 717 | BTDeviceItem* device; |
706 | for (; it.current(); ++it ) | 718 | for (; it.current(); ++it ) |
707 | { | 719 | { |
708 | item = (BTListItem*) it.current(); | 720 | item = (BTListItem*) it.current(); |
709 | if ( item->typeId() != BTListItem::Device ) | 721 | if ( item->typeId() != BTListItem::Device ) |
710 | continue; | 722 | continue; |
711 | 723 | ||
712 | device = (BTDeviceItem*)item; | 724 | device = (BTDeviceItem*)item; |
713 | if ( rem.equals( device->remoteDevice() ) ) | 725 | if ( rem.equals( device->remoteDevice() ) ) |
714 | return true; | 726 | return true; |
715 | } | 727 | } |
716 | return false; // not found | 728 | return false; // not found |
717 | } | 729 | } |
718 | 730 | ||
719 | /** | 731 | /** |
720 | * Start process of the cell phone forwarding | 732 | * Start process of the cell phone forwarding |
721 | */ | 733 | */ |
722 | void BlueBase::doForward() | 734 | void BlueBase::doForward() |
723 | { | 735 | { |
724 | if (forwarder && forwarder->isRunning()) { | 736 | if (forwarder && forwarder->isRunning()) { |
725 | runButton->setText("start gateway"); | 737 | runButton->setText("start gateway"); |
726 | forwarder->stop(); | 738 | forwarder->stop(); |
727 | delete forwarder; | 739 | delete forwarder; |
728 | forwarder = NULL; | 740 | forwarder = NULL; |
729 | return; | 741 | return; |
730 | } | 742 | } |
731 | QString str = serDevName->text(); | 743 | QString str = serDevName->text(); |
732 | forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); | 744 | forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); |
733 | connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)), | 745 | connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)), |
734 | this, SLOT(forwardExited(Opie::Core::OProcess*))); | 746 | this, SLOT(forwardExited(Opie::Core::OProcess*))); |
735 | if (forwarder->start(OProcess::NotifyOnExit) < 0) { | 747 | if (forwarder->start(OProcess::NotifyOnExit) < 0) { |
736 | QMessageBox::critical(this, tr("Forwarder Error"), | 748 | QMessageBox::critical(this, tr("Forwarder Error"), |
737 | tr("Forwarder start error:") + tr(strerror(errno))); | 749 | tr("Forwarder start error:") + tr(strerror(errno))); |
738 | return; | 750 | return; |
739 | } | 751 | } |
740 | runButton->setText("stop gateway"); | 752 | runButton->setText("stop gateway"); |
753 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
754 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)") | ||
755 | << QPEApplication::DisableSuspend; | ||
756 | #endif | ||
741 | } | 757 | } |
742 | 758 | ||
743 | /** | 759 | /** |
744 | * React on the process end | 760 | * React on the process end |
745 | */ | 761 | */ |
746 | void BlueBase::forwardExit(Opie::Core::OProcess* proc) | 762 | void BlueBase::forwardExit(Opie::Core::OProcess* proc) |
747 | { | 763 | { |
764 | #if defined(Q_WS_QWS) && !defined(QT_NO_COP) | ||
765 | QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) | ||
766 | << QPEApplication::Enable; | ||
767 | #endif | ||
748 | if (proc->exitStatus() != 0) | 768 | if (proc->exitStatus() != 0) |
749 | QMessageBox::critical(this, tr("Forwarder Error"), | 769 | QMessageBox::critical(this, tr("Forwarder Error"), |
750 | tr("Forwarder start error")); | 770 | tr("Forwarder start error")); |
751 | delete proc; | 771 | delete proc; |
752 | forwarder = NULL; | 772 | forwarder = NULL; |
753 | runButton->setText("start gateway"); | 773 | runButton->setText("start gateway"); |
754 | } | 774 | } |
755 | 775 | ||
756 | /** | 776 | /** |
757 | * Encrypt entered passkey | 777 | * Encrypt entered passkey |
758 | * doit - do encryption of the key | 778 | * doit - do encryption of the key |
759 | */ | 779 | */ |
760 | void BlueBase::doEncrypt(bool doit) | 780 | void BlueBase::doEncrypt(bool doit) |
761 | { | 781 | { |
762 | passkeyLine->setEchoMode((doit)? QLineEdit::Password: QLineEdit::Normal); | 782 | passkeyLine->setEchoMode((doit)? QLineEdit::Password: QLineEdit::Normal); |
763 | } | 783 | } |
764 | 784 | ||
765 | /** | 785 | /** |
766 | * Start services edit dialog | 786 | * Start services edit dialog |
767 | */ | 787 | */ |
768 | void BlueBase::editServices() | 788 | void BlueBase::editServices() |
769 | { | 789 | { |
770 | QString conf = "/etc/default/bluetooth"; | 790 | QString conf = "/etc/default/bluetooth"; |
771 | //// Use for debugging purposes | 791 | //// Use for debugging purposes |
772 | //// QString conf = "/mnt/net/opie/bin/bluetooth"; | 792 | //// QString conf = "/mnt/net/opie/bin/bluetooth"; |
773 | ServicesDialog svcEdit(conf, this, "ServicesDialog", true, | 793 | ServicesDialog svcEdit(conf, this, "ServicesDialog", true, |
774 | WStyle_ContextHelp); | 794 | WStyle_ContextHelp); |
775 | 795 | ||
776 | if (QPEApplication::execDialog(&svcEdit) == QDialog::Accepted) | 796 | if (QPEApplication::execDialog(&svcEdit) == QDialog::Accepted) |
777 | { | 797 | { |
778 | } | 798 | } |
779 | } | 799 | } |
780 | 800 | ||
781 | //eof | 801 | //eof |