author | zecke <zecke> | 2002-07-13 13:31:50 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-07-13 13:31:50 (UTC) |
commit | 21e275324433ac4902c89997b53cbb042bdca9ab (patch) (unidiff) | |
tree | 3c1aca780dcc3ed36cae580cd69eb25f0b6fc2f3 | |
parent | d7f3722f9b7913731978437085b14cc2cccbfa24 (diff) | |
download | opie-21e275324433ac4902c89997b53cbb042bdca9ab.zip opie-21e275324433ac4902c89997b53cbb042bdca9ab.tar.gz opie-21e275324433ac4902c89997b53cbb042bdca9ab.tar.bz2 |
Factory code is in place... aye
Now we just need FactoryImpl of
OBEX,RfcCom,VoiceGateWay
There will be one small adjustment though
QListViewItem -> BTDeviceItem
-rw-r--r-- | noncore/net/opietooth/manager/bluebase.cpp | 56 | ||||
-rw-r--r-- | noncore/net/opietooth/manager/popuphelper.cpp | 2 |
2 files changed, 44 insertions, 14 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp index 189001d..3f2f138 100644 --- a/noncore/net/opietooth/manager/bluebase.cpp +++ b/noncore/net/opietooth/manager/bluebase.cpp | |||
@@ -1,460 +1,488 @@ | |||
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 | 21 | ||
22 | #include <qframe.h> | 22 | #include <qframe.h> |
23 | #include <qlabel.h> | 23 | #include <qlabel.h> |
24 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
25 | #include <qlayout.h> | 25 | #include <qlayout.h> |
26 | #include <qvariant.h> | 26 | #include <qvariant.h> |
27 | #include <qwhatsthis.h> | 27 | #include <qwhatsthis.h> |
28 | #include <qimage.h> | 28 | #include <qimage.h> |
29 | #include <qpixmap.h> | 29 | #include <qpixmap.h> |
30 | #include <qtabwidget.h> | 30 | #include <qtabwidget.h> |
31 | #include <qscrollview.h> | 31 | #include <qscrollview.h> |
32 | #include <qvbox.h> | 32 | #include <qvbox.h> |
33 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
34 | #include <qcheckbox.h> | 34 | #include <qcheckbox.h> |
35 | #include <qlineedit.h> | 35 | #include <qlineedit.h> |
36 | #include <qlistview.h> | 36 | #include <qlistview.h> |
37 | #include <qdir.h> | 37 | #include <qdir.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | #include <qtimer.h> | 39 | #include <qtimer.h> |
40 | 40 | ||
41 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
42 | #include <qpe/config.h> | 42 | #include <qpe/config.h> |
43 | 43 | ||
44 | #include <remotedevice.h> | 44 | #include <remotedevice.h> |
45 | #include <services.h> | 45 | #include <services.h> |
46 | 46 | ||
47 | #include "btconnectionitem.h" | 47 | #include "btconnectionitem.h" |
48 | 48 | ||
49 | using namespace OpieTooth; | 49 | using namespace OpieTooth; |
50 | 50 | ||
51 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) | 51 | BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) |
52 | : BluetoothBase( parent, name, fl ) { | 52 | : BluetoothBase( parent, name, fl ) { |
53 | 53 | ||
54 | m_localDevice = new Manager( "hci0" ); | 54 | m_localDevice = new Manager( "hci0" ); |
55 | 55 | ||
56 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); | 56 | connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); |
57 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); | 57 | connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); |
58 | // not good since lib is async | 58 | // not good since lib is async |
59 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), | 59 | // connect( ListView2, SIGNAL( expanded ( QListViewItem* ) ), |
60 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); | 60 | // this, SLOT( addServicesToDevice( QListViewItem * ) ) ); |
61 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), | 61 | connect( ListView2, SIGNAL( clicked( QListViewItem* )), |
62 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); | 62 | this, SLOT( startServiceActionClicked( QListViewItem* ) ) ); |
63 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), | 63 | connect( ListView2, SIGNAL( rightButtonClicked( QListViewItem *, const QPoint &, int ) ), |
64 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); | 64 | this, SLOT(startServiceActionHold( QListViewItem *, const QPoint &, int) ) ); |
65 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), | 65 | connect( m_localDevice , SIGNAL( foundServices( const QString& , Services::ValueList ) ), |
66 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); | 66 | this, SLOT( addServicesToDevice( const QString& , Services::ValueList ) ) ); |
67 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), | 67 | connect( m_localDevice, SIGNAL( available( const QString&, bool ) ), |
68 | this, SLOT( deviceActive( const QString& , bool ) ) ); | 68 | this, SLOT( deviceActive( const QString& , bool ) ) ); |
69 | connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), | 69 | connect( m_localDevice, SIGNAL( connections( Connection::ValueList ) ), |
70 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); | 70 | this, SLOT( addConnectedDevices( Connection::ValueList ) ) ); |
71 | 71 | ||
72 | //Load all icons needed | 72 | //Load all icons needed |
73 | m_offPix = Resource::loadPixmap( "editdelete" ); | 73 | m_offPix = Resource::loadPixmap( "editdelete" ); |
74 | m_onPix = Resource::loadPixmap( "installed" ); | 74 | m_onPix = Resource::loadPixmap( "installed" ); |
75 | 75 | ||
76 | QPalette pal = this->palette(); | 76 | QPalette pal = this->palette(); |
77 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); | 77 | QColor col = pal.color( QPalette::Active, QColorGroup::Background ); |
78 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); | 78 | pal.setColor( QPalette::Active, QColorGroup::Button, col ); |
79 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); | 79 | pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); |
80 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); | 80 | pal.setColor( QPalette::Normal, QColorGroup::Button, col ); |
81 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); | 81 | pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); |
82 | this->setPalette( pal ); | 82 | this->setPalette( pal ); |
83 | 83 | ||
84 | setCaption( tr( "Bluetooth Manager" ) ); | 84 | setCaption( tr( "Bluetooth Manager" ) ); |
85 | 85 | ||
86 | readConfig(); | 86 | readConfig(); |
87 | initGui(); | 87 | initGui(); |
88 | 88 | ||
89 | //TESTING | 89 | //TESTING |
90 | ListView2->setRootIsDecorated(true); | 90 | ListView2->setRootIsDecorated(true); |
91 | 91 | ||
92 | BTDeviceItem *topLV2 = new BTDeviceItem( ListView2, RemoteDevice("xx:", "Siemens S45" ) ); | 92 | BTDeviceItem *topLV2 = new BTDeviceItem( ListView2, RemoteDevice("xx:", "Siemens S45" ) ); |
93 | topLV2->setPixmap( 1, m_onPix ); | 93 | topLV2->setPixmap( 1, m_onPix ); |
94 | Services s1; | 94 | Services s1; |
95 | s1.setServiceName( "Serial" ); | 95 | s1.setServiceName( "Serial" ); |
96 | s1.insertClassId(1, "BlueNic"); | ||
96 | (void) new BTServiceItem( topLV2, s1 ); | 97 | (void) new BTServiceItem( topLV2, s1 ); |
97 | s1.setServiceName( "BlueNic" ); | 98 | s1.setServiceName( "BlueNic" ); |
99 | s1.insertClassId(2, "Obex"); | ||
98 | (void) new BTServiceItem( topLV2, s1 ); | 100 | (void) new BTServiceItem( topLV2, s1 ); |
99 | 101 | ||
100 | writeToHciConfig(); | 102 | writeToHciConfig(); |
101 | // search conncetions | 103 | // search conncetions |
102 | addConnectedDevices(); | 104 | addConnectedDevices(); |
103 | m_iconLoader = new BTIconLoader(); | 105 | m_iconLoader = new BTIconLoader(); |
104 | } | 106 | } |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * Reads all options from the config file | 109 | * Reads all options from the config file |
108 | */ | 110 | */ |
109 | void BlueBase::readConfig() { | 111 | void BlueBase::readConfig() { |
110 | 112 | ||
111 | Config cfg( "bluetoothmanager" ); | 113 | Config cfg( "bluetoothmanager" ); |
112 | cfg.setGroup( "bluezsettings" ); | 114 | cfg.setGroup( "bluezsettings" ); |
113 | 115 | ||
114 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with | 116 | m_deviceName = cfg.readEntry( "name" , "No name" ); // name the device should identify with |
115 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak | 117 | m_defaultPasskey = cfg.readEntryCrypt( "passkey" , "" ); // <- hmm, look up how good the trolls did that, maybe too weak |
116 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); | 118 | m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); |
117 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); | 119 | m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); |
118 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); | 120 | m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); |
119 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); | 121 | m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); |
120 | } | 122 | } |
121 | 123 | ||
122 | /** | 124 | /** |
123 | * Writes all options to the config file | 125 | * Writes all options to the config file |
124 | */ | 126 | */ |
125 | void BlueBase::writeConfig() { | 127 | void BlueBase::writeConfig() { |
126 | 128 | ||
127 | Config cfg( "bluetoothmanager" ); | 129 | Config cfg( "bluetoothmanager" ); |
128 | cfg.setGroup( "bluezsettings" ); | 130 | cfg.setGroup( "bluezsettings" ); |
129 | 131 | ||
130 | cfg.writeEntry( "name" , m_deviceName ); | 132 | cfg.writeEntry( "name" , m_deviceName ); |
131 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); | 133 | cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); |
132 | cfg.writeEntry( "useEncryption" , m_useEncryption ); | 134 | cfg.writeEntry( "useEncryption" , m_useEncryption ); |
133 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); | 135 | cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); |
134 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); | 136 | cfg.writeEntry( "enablePagescan" , m_enablePagescan ); |
135 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); | 137 | cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); |
136 | 138 | ||
137 | writeToHciConfig(); | 139 | writeToHciConfig(); |
138 | } | 140 | } |
139 | 141 | ||
140 | void BlueBase::writeToHciConfig() { | 142 | void BlueBase::writeToHciConfig() { |
141 | 143 | ||
142 | HciConfWrapper hciconf ( "/tmp/hcid.conf" ); | 144 | HciConfWrapper hciconf ( "/tmp/hcid.conf" ); |
143 | hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); | 145 | hciconf.setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); |
144 | 146 | ||
145 | 147 | ||
146 | // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); | 148 | // hciconf->setPinHelper( "/bin/QtPalmtop/bin/blue-pin" ); |
147 | 149 | ||
148 | hciconf.setName( m_deviceName ); | 150 | hciconf.setName( m_deviceName ); |
149 | hciconf.setEncrypt( m_useEncryption ); | 151 | hciconf.setEncrypt( m_useEncryption ); |
150 | hciconf.setAuth( m_enableAuthentification ); | 152 | hciconf.setAuth( m_enableAuthentification ); |
151 | hciconf.setPscan( m_enablePagescan ); | 153 | hciconf.setPscan( m_enablePagescan ); |
152 | hciconf.setIscan( m_enableInquiryscan ); | 154 | hciconf.setIscan( m_enableInquiryscan ); |
153 | } | 155 | } |
154 | 156 | ||
155 | 157 | ||
156 | /** | 158 | /** |
157 | * Read the list of allready known devices | 159 | * Read the list of allready known devices |
158 | * | 160 | * |
159 | */ | 161 | */ |
160 | void BlueBase::readSavedDevices() { | 162 | void BlueBase::readSavedDevices() { |
161 | 163 | ||
162 | QValueList<RemoteDevice> loadedDevices; | 164 | QValueList<RemoteDevice> loadedDevices; |
163 | 165 | ||
164 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); | 166 | QDir deviceListSave( QDir::homeDirPath() + "/Settings/bluetooth/"); |
165 | // list of .conf files | 167 | // list of .conf files |
166 | QStringList devicesFileList = deviceListSave.entryList(); | 168 | QStringList devicesFileList = deviceListSave.entryList(); |
167 | 169 | ||
168 | // cut .conf of to get the mac and also read the name entry in it. | 170 | // cut .conf of to get the mac and also read the name entry in it. |
169 | 171 | ||
170 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { | 172 | for ( QStringList::Iterator it = devicesFileList.begin(); it != devicesFileList.end(); ++it ) { |
171 | 173 | ||
172 | QString name; | 174 | QString name; |
173 | QString mac; | 175 | QString mac; |
174 | qDebug((*it).latin1() ); | 176 | qDebug((*it).latin1() ); |
175 | Config conf((*it)); | 177 | Config conf((*it)); |
176 | conf.setGroup("Info"); | 178 | conf.setGroup("Info"); |
177 | name = conf.readEntry("name", "Error"); | 179 | name = conf.readEntry("name", "Error"); |
178 | qDebug("MAC: " + mac); | 180 | qDebug("MAC: " + mac); |
179 | qDebug("NAME: " + name); | 181 | qDebug("NAME: " + name); |
180 | RemoteDevice currentDevice( mac , name ); | 182 | RemoteDevice currentDevice( mac , name ); |
181 | loadedDevices.append( currentDevice ); | 183 | loadedDevices.append( currentDevice ); |
182 | } | 184 | } |
183 | addSearchedDevices( loadedDevices ); | 185 | addSearchedDevices( loadedDevices ); |
184 | } | 186 | } |
185 | 187 | ||
186 | /** | 188 | /** |
187 | * Write the list of allready known devices | 189 | * Write the list of allready known devices |
188 | * | 190 | * |
189 | */ | 191 | */ |
190 | void BlueBase::writeSavedDevices() { | 192 | void BlueBase::writeSavedDevices() { |
191 | QListViewItemIterator it( ListView2 ); | 193 | QListViewItemIterator it( ListView2 ); |
192 | BTListItem* item; | 194 | BTListItem* item; |
193 | BTDeviceItem* device; | 195 | BTDeviceItem* device; |
194 | 196 | ||
195 | for ( ; it.current(); ++it ) { | 197 | for ( ; it.current(); ++it ) { |
196 | item = (BTListItem*)it.current(); | 198 | item = (BTListItem*)it.current(); |
197 | if(item->typeId() != BTListItem::Device ) | 199 | if(item->typeId() != BTListItem::Device ) |
198 | continue; | 200 | continue; |
199 | device = (BTDeviceItem*)item; | 201 | device = (BTDeviceItem*)item; |
200 | // seperate config file for each device, to store more information in future. | 202 | // seperate config file for each device, to store more information in future. |
201 | qDebug( "/Settings/bluetooth/" + device->mac() + ".conf"); | 203 | qDebug( "/Settings/bluetooth/" + device->mac() + ".conf"); |
202 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File ); | 204 | Config conf( QDir::homeDirPath() + "/Settings/bluetooth/" + device->mac() + ".conf", Config::File ); |
203 | conf.setGroup( "Info" ); | 205 | conf.setGroup( "Info" ); |
204 | conf.writeEntry( "name", device->name() ); | 206 | conf.writeEntry( "name", device->name() ); |
205 | } | 207 | } |
206 | } | 208 | } |
207 | 209 | ||
208 | 210 | ||
209 | /** | 211 | /** |
210 | * Set up the gui | 212 | * Set up the gui |
211 | */ | 213 | */ |
212 | void BlueBase::initGui() { | 214 | void BlueBase::initGui() { |
213 | StatusLabel->setText( status() ); // maybe move it to getStatus() | 215 | StatusLabel->setText( status() ); // maybe move it to getStatus() |
214 | cryptCheckBox->setChecked( m_useEncryption ); | 216 | cryptCheckBox->setChecked( m_useEncryption ); |
215 | authCheckBox->setChecked( m_enableAuthentification ); | 217 | authCheckBox->setChecked( m_enableAuthentification ); |
216 | pagescanCheckBox->setChecked( m_enablePagescan ); | 218 | pagescanCheckBox->setChecked( m_enablePagescan ); |
217 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); | 219 | inquiryscanCheckBox->setChecked( m_enableInquiryscan ); |
218 | deviceNameLine->setText( m_deviceName ); | 220 | deviceNameLine->setText( m_deviceName ); |
219 | passkeyLine->setText( m_defaultPasskey ); | 221 | passkeyLine->setText( m_defaultPasskey ); |
220 | // set info tab | 222 | // set info tab |
221 | setInfo(); | 223 | setInfo(); |
222 | } | 224 | } |
223 | 225 | ||
224 | 226 | ||
225 | /** | 227 | /** |
226 | * Get the status informations and returns it | 228 | * Get the status informations and returns it |
227 | * @return QString the status informations gathered | 229 | * @return QString the status informations gathered |
228 | */ | 230 | */ |
229 | QString BlueBase::status()const{ | 231 | QString BlueBase::status()const{ |
230 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); | 232 | QString infoString = tr( "<b>Device name : </b> Ipaq" ); |
231 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); | 233 | infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); |
232 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); | 234 | infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); |
233 | 235 | ||
234 | return (infoString); | 236 | return (infoString); |
235 | } | 237 | } |
236 | 238 | ||
237 | 239 | ||
238 | /** | 240 | /** |
239 | * Read the current values from the gui and invoke writeConfig() | 241 | * Read the current values from the gui and invoke writeConfig() |
240 | */ | 242 | */ |
241 | void BlueBase::applyConfigChanges() { | 243 | void BlueBase::applyConfigChanges() { |
242 | m_deviceName = deviceNameLine->text(); | 244 | m_deviceName = deviceNameLine->text(); |
243 | m_defaultPasskey = passkeyLine->text(); | 245 | m_defaultPasskey = passkeyLine->text(); |
244 | m_useEncryption = cryptCheckBox->isChecked(); | 246 | m_useEncryption = cryptCheckBox->isChecked(); |
245 | m_enableAuthentification = authCheckBox->isChecked(); | 247 | m_enableAuthentification = authCheckBox->isChecked(); |
246 | m_enablePagescan = pagescanCheckBox->isChecked(); | 248 | m_enablePagescan = pagescanCheckBox->isChecked(); |
247 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); | 249 | m_enableInquiryscan = inquiryscanCheckBox->isChecked(); |
248 | 250 | ||
249 | writeConfig(); | 251 | writeConfig(); |
250 | 252 | ||
251 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); | 253 | QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); |
252 | } | 254 | } |
253 | 255 | ||
254 | /** | 256 | /** |
255 | * Add fresh found devices from scan dialog to the listing | 257 | * Add fresh found devices from scan dialog to the listing |
256 | * | 258 | * |
257 | */ | 259 | */ |
258 | void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { | 260 | void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) { |
259 | BTDeviceItem * deviceItem; | 261 | BTDeviceItem * deviceItem; |
260 | QValueList<RemoteDevice>::ConstIterator it; | 262 | QValueList<RemoteDevice>::ConstIterator it; |
261 | 263 | ||
262 | for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { | 264 | for( it = newDevices.begin(); it != newDevices.end() ; ++it ) { |
263 | 265 | ||
264 | deviceItem = new BTDeviceItem( ListView2 , (*it) ); | 266 | deviceItem = new BTDeviceItem( ListView2 , (*it) ); |
265 | deviceItem->setExpandable ( true ); | 267 | deviceItem->setExpandable ( true ); |
266 | 268 | ||
267 | // look if device is avail. atm, async | 269 | // look if device is avail. atm, async |
268 | deviceActive( (*it) ); | 270 | deviceActive( (*it) ); |
269 | 271 | ||
270 | // ggf auch hier? | 272 | // ggf auch hier? |
271 | addServicesToDevice( deviceItem ); | 273 | addServicesToDevice( deviceItem ); |
272 | } | 274 | } |
273 | } | 275 | } |
274 | 276 | ||
275 | 277 | ||
276 | /** | 278 | /** |
277 | * Action that is toggled on entrys on click | 279 | * Action that is toggled on entrys on click |
278 | */ | 280 | */ |
279 | void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { | 281 | void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) { |
280 | } | 282 | } |
281 | 283 | ||
282 | /** | 284 | /** |
283 | * Action that are toggled on hold (mostly QPopups i guess) | 285 | * Action that are toggled on hold (mostly QPopups i guess) |
284 | */ | 286 | */ |
285 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { | 287 | void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) { |
286 | 288 | ||
287 | QPopupMenu *menu = new QPopupMenu(); | 289 | QPopupMenu *menu = new QPopupMenu(); |
288 | int ret=0; | 290 | int ret=0; |
289 | 291 | ||
290 | if ( ((BTListItem*)item)->type() == "device") { | 292 | if ( ((BTListItem*)item)->type() == "device") { |
291 | 293 | ||
292 | QPopupMenu *groups = new QPopupMenu(); | 294 | QPopupMenu *groups = new QPopupMenu(); |
293 | 295 | ||
294 | menu->insertItem( tr("rescan sevices:"), 0); | 296 | menu->insertItem( tr("rescan sevices:"), 0); |
295 | menu->insertItem( tr("to group"), groups , 1); | 297 | menu->insertItem( tr("to group"), groups , 1); |
296 | menu->insertItem( tr("bound device"), 2); | 298 | menu->insertItem( tr("bound device"), 2); |
297 | menu->insertItem( tr("delete"), 3); | 299 | menu->insertItem( tr("delete"), 3); |
298 | 300 | ||
299 | ret = menu->exec( point , 0); | 301 | ret = menu->exec( point , 0); |
300 | 302 | ||
301 | switch(ret) { | 303 | switch(ret) { |
302 | case 0: | 304 | case -1: |
305 | |||
303 | break; | 306 | break; |
304 | case 1: | 307 | case 1: |
305 | break; | 308 | break; |
306 | case 2: | 309 | case 2: |
307 | // make connection | 310 | // make connection |
308 | break; | 311 | break; |
309 | case 3: | 312 | case 3: |
310 | // delete childs too | 313 | // delete childs too |
311 | delete item; | 314 | delete item; |
312 | break; | 315 | break; |
313 | } | 316 | } |
314 | delete groups; | 317 | delete groups; |
315 | 318 | ||
316 | } else if ( ((BTListItem*)item)->type() == "service") { | 319 | } |
320 | /** | ||
321 | * We got service sensitive PopupMenus in our factory | ||
322 | * We will create one through the factory and will insert | ||
323 | * our Separator + ShowInfo into the menu or create a new | ||
324 | * one if the factory returns 0 | ||
325 | * PopupMenu deletion is kind of weird. | ||
326 | * If escaped( -1 ) or any of our items were chosen we'll | ||
327 | * delete the PopupMenu otherwise it's the responsibility of | ||
328 | * the PopupMenu to delete itself | ||
329 | * | ||
330 | */ | ||
331 | else if ( ((BTListItem*)item)->type() == "service") { | ||
332 | BTServiceItem* service = (BTServiceItem*)item; | ||
333 | QMap<int, QString> list = service->services().classIdList(); | ||
334 | QMap<int, QString>::Iterator it = list.begin(); | ||
335 | QPopupMenu *popup =0l; | ||
336 | if ( it != list.end() ) | ||
337 | popup = m_popHelper.find( it.key(), | ||
338 | service->services(), | ||
339 | service->parent() ); | ||
340 | |||
341 | if ( popup == 0l ) { | ||
342 | qWarning("factory returned 0l"); | ||
343 | popup = new QPopupMenu(); | ||
344 | } | ||
317 | 345 | ||
318 | menu->insertItem( tr("Test1:"), 0); | 346 | int test1 = popup->insertItem( tr("Test1:"), 0); |
319 | menu->insertItem( tr("connect"), 1); | 347 | int con = popup->insertItem( tr("connect"), 1); |
320 | menu->insertItem( tr("delete"), 2); | 348 | int del = popup->insertItem( tr("delete"), 2); |
321 | 349 | ||
322 | ret = menu->exec( point , 0); | 350 | ret = popup->exec( point ); |
323 | 351 | ||
324 | switch(ret) { | 352 | if ( ret == -1 ) |
325 | case 0: | 353 | delete popup; |
326 | break; | 354 | else if ( ret == test1 ) |
327 | case 1: | 355 | delete popup; |
328 | break; | 356 | else if ( ret == con ) |
329 | case 2: | 357 | delete popup; |
330 | // delete childs too | 358 | else if ( ret == del ) { |
359 | // take item first? -zecke | ||
331 | delete item; | 360 | delete item; |
332 | break; | ||
333 | } | 361 | } |
334 | } | 362 | } |
335 | delete menu; | 363 | delete menu; |
336 | } | 364 | } |
337 | 365 | ||
338 | /** | 366 | /** |
339 | * Search and display avail. services for a device (on expand from device listing) | 367 | * Search and display avail. services for a device (on expand from device listing) |
340 | * | 368 | * |
341 | */ | 369 | */ |
342 | void BlueBase::addServicesToDevice( BTDeviceItem * item ) { | 370 | void BlueBase::addServicesToDevice( BTDeviceItem * item ) { |
343 | qDebug("addServicesToDevice"); | 371 | qDebug("addServicesToDevice"); |
344 | // row of mac adress text(3) | 372 | // row of mac adress text(3) |
345 | RemoteDevice device = item->remoteDevice(); | 373 | RemoteDevice device = item->remoteDevice(); |
346 | m_deviceList.insert( item->mac() , item ); | 374 | m_deviceList.insert( item->mac() , item ); |
347 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back | 375 | // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back |
348 | m_localDevice->searchServices( device ); | 376 | m_localDevice->searchServices( device ); |
349 | } | 377 | } |
350 | 378 | ||
351 | 379 | ||
352 | /** | 380 | /** |
353 | * Overloaded. This one it the one that is connected to the foundServices signal | 381 | * Overloaded. This one it the one that is connected to the foundServices signal |
354 | * @param device the mac address of the remote device | 382 | * @param device the mac address of the remote device |
355 | * @param servicesList the list with the service the device has. | 383 | * @param servicesList the list with the service the device has. |
356 | */ | 384 | */ |
357 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { | 385 | void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) { |
358 | qDebug("fill services list"); | 386 | qDebug("fill services list"); |
359 | 387 | ||
360 | QMap<QString,BTDeviceItem*>::Iterator it; | 388 | QMap<QString,BTDeviceItem*>::Iterator it; |
361 | BTDeviceItem* deviceItem = 0; | 389 | BTDeviceItem* deviceItem = 0; |
362 | 390 | ||
363 | // get the right devices which requested the search | 391 | // get the right devices which requested the search |
364 | it = m_deviceList.find( device ); | 392 | it = m_deviceList.find( device ); |
365 | if( it == m_deviceList.end() ) | 393 | if( it == m_deviceList.end() ) |
366 | return; | 394 | return; |
367 | deviceItem = it.data(); | 395 | deviceItem = it.data(); |
368 | 396 | ||
369 | QValueList<OpieTooth::Services>::Iterator it2; | 397 | QValueList<OpieTooth::Services>::Iterator it2; |
370 | BTServiceItem * serviceItem; | 398 | BTServiceItem * serviceItem; |
371 | 399 | ||
372 | if (!servicesList.isEmpty() ) { | 400 | if (!servicesList.isEmpty() ) { |
373 | // add services | 401 | // add services |
374 | QMap<int, QString> list; | 402 | QMap<int, QString> list; |
375 | QMap<int, QString>::Iterator classIt; | 403 | QMap<int, QString>::Iterator classIt; |
376 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { | 404 | for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) { |
377 | serviceItem = new BTServiceItem( deviceItem , (*it2) ); | 405 | serviceItem = new BTServiceItem( deviceItem , (*it2) ); |
378 | list = (*it2).classIdList(); | 406 | list = (*it2).classIdList(); |
379 | classIt = list.begin(); | 407 | classIt = list.begin(); |
380 | int classId; | 408 | int classId; |
381 | if ( classIt != list.end() ) | 409 | if ( classIt != list.end() ) |
382 | classId = classIt.key(); | 410 | classId = classIt.key(); |
383 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); | 411 | serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); |
384 | } | 412 | } |
385 | } else { | 413 | } else { |
386 | Services s1; | 414 | Services s1; |
387 | s1.setServiceName( tr("no serives found") ); | 415 | s1.setServiceName( tr("no serives found") ); |
388 | serviceItem = new BTServiceItem( deviceItem, s1 ); | 416 | serviceItem = new BTServiceItem( deviceItem, s1 ); |
389 | } | 417 | } |
390 | // now remove them from the list | 418 | // now remove them from the list |
391 | m_deviceList.remove( it ); | 419 | m_deviceList.remove( it ); |
392 | } | 420 | } |
393 | 421 | ||
394 | 422 | ||
395 | /** | 423 | /** |
396 | * Add the existing connections (pairs) to the connections tab. | 424 | * Add the existing connections (pairs) to the connections tab. |
397 | * This one triggers the search | 425 | * This one triggers the search |
398 | */ | 426 | */ |
399 | void BlueBase::addConnectedDevices() { | 427 | void BlueBase::addConnectedDevices() { |
400 | m_localDevice->searchConnections(); | 428 | m_localDevice->searchConnections(); |
401 | } | 429 | } |
402 | 430 | ||
403 | 431 | ||
404 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { | 432 | void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) { |
405 | QValueList<OpieTooth::ConnectionState>::Iterator it; | 433 | QValueList<OpieTooth::ConnectionState>::Iterator it; |
406 | BTConnectionItem * connectionItem; | 434 | BTConnectionItem * connectionItem; |
407 | 435 | ||
408 | if ( !connectionList.isEmpty() ) { | 436 | if ( !connectionList.isEmpty() ) { |
409 | 437 | ||
410 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { | 438 | for (it = connectionList.begin(); it != connectionList.end(); ++it) { |
411 | connectionItem = new BTConnectionItem( ListView4 , (*it) ); | 439 | connectionItem = new BTConnectionItem( ListView4 , (*it) ); |
412 | } | 440 | } |
413 | } else { | 441 | } else { |
414 | ConnectionState con; | 442 | ConnectionState con; |
415 | con.setMac( tr("No connections found") ); | 443 | con.setMac( tr("No connections found") ); |
416 | connectionItem = new BTConnectionItem( ListView4 , con ); | 444 | connectionItem = new BTConnectionItem( ListView4 , con ); |
417 | } | 445 | } |
418 | 446 | ||
419 | // recall connection search after some time | 447 | // recall connection search after some time |
420 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); | 448 | QTimer::singleShot( 20000, this, SLOT( addConnectedDevices() ) ); |
421 | } | 449 | } |
422 | 450 | ||
423 | /** | 451 | /** |
424 | * Find out if a device can currently be reached | 452 | * Find out if a device can currently be reached |
425 | */ | 453 | */ |
426 | void BlueBase::deviceActive( const RemoteDevice &device ) { | 454 | void BlueBase::deviceActive( const RemoteDevice &device ) { |
427 | // search by mac, async, gets a signal back | 455 | // search by mac, async, gets a signal back |
428 | // We should have a BTDeviceItem there or where does it get added to the map -zecke | 456 | // We should have a BTDeviceItem there or where does it get added to the map -zecke |
429 | m_localDevice->isAvailable( device.mac() ); | 457 | m_localDevice->isAvailable( device.mac() ); |
430 | } | 458 | } |
431 | 459 | ||
432 | /** | 460 | /** |
433 | * The signal catcher. Set the avail. status on device. | 461 | * The signal catcher. Set the avail. status on device. |
434 | * @param device - the mac address | 462 | * @param device - the mac address |
435 | * @param connected - if it is avail. or not | 463 | * @param connected - if it is avail. or not |
436 | */ | 464 | */ |
437 | void BlueBase::deviceActive( const QString& device, bool connected ) { | 465 | void BlueBase::deviceActive( const QString& device, bool connected ) { |
438 | qDebug("deviceActive slot"); | 466 | qDebug("deviceActive slot"); |
439 | 467 | ||
440 | QMap<QString,BTDeviceItem*>::Iterator it; | 468 | QMap<QString,BTDeviceItem*>::Iterator it; |
441 | 469 | ||
442 | it = m_deviceList.find( device ); | 470 | it = m_deviceList.find( device ); |
443 | if( it == m_deviceList.end() ) | 471 | if( it == m_deviceList.end() ) |
444 | return; | 472 | return; |
445 | 473 | ||
446 | BTDeviceItem* deviceItem = it.data(); | 474 | BTDeviceItem* deviceItem = it.data(); |
447 | 475 | ||
448 | 476 | ||
449 | if ( connected ) { | 477 | if ( connected ) { |
450 | deviceItem->setPixmap( 1, m_onPix ); | 478 | deviceItem->setPixmap( 1, m_onPix ); |
451 | } else { | 479 | } else { |
452 | deviceItem->setPixmap( 1, m_offPix ); | 480 | deviceItem->setPixmap( 1, m_offPix ); |
453 | } | 481 | } |
454 | m_deviceList.remove( it ); | 482 | m_deviceList.remove( it ); |
455 | } | 483 | } |
456 | 484 | ||
457 | /** | 485 | /** |
458 | * Open the "scan for devices" dialog | 486 | * Open the "scan for devices" dialog |
459 | */ | 487 | */ |
460 | void BlueBase::startScan() { | 488 | void BlueBase::startScan() { |
diff --git a/noncore/net/opietooth/manager/popuphelper.cpp b/noncore/net/opietooth/manager/popuphelper.cpp index d8404d6..26c4b02 100644 --- a/noncore/net/opietooth/manager/popuphelper.cpp +++ b/noncore/net/opietooth/manager/popuphelper.cpp | |||
@@ -1,28 +1,30 @@ | |||
1 | 1 | ||
2 | #include "stdpopups.h" | 2 | #include "stdpopups.h" |
3 | 3 | ||
4 | #include "popuphelper.h" | 4 | #include "popuphelper.h" |
5 | 5 | ||
6 | using namespace OpieTooth; | 6 | using namespace OpieTooth; |
7 | 7 | ||
8 | PopupHelper::PopupHelper() { | 8 | PopupHelper::PopupHelper() { |
9 | init(); | 9 | init(); |
10 | } | 10 | } |
11 | PopupHelper::~PopupHelper() { | 11 | PopupHelper::~PopupHelper() { |
12 | 12 | ||
13 | } | 13 | } |
14 | void PopupHelper::insert( int id, popupFactory fact ) { | 14 | void PopupHelper::insert( int id, popupFactory fact ) { |
15 | m_map.insert(id, fact ); | 15 | m_map.insert(id, fact ); |
16 | } | 16 | } |
17 | QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) { | 17 | QPopupMenu* PopupHelper::find( int id, const Services& ser, QListViewItem* item ) { |
18 | qWarning("find"); | ||
18 | FactoryMap::Iterator it = m_map.find(id ); | 19 | FactoryMap::Iterator it = m_map.find(id ); |
19 | if ( it != m_map.end() ) { | 20 | if ( it != m_map.end() ) { |
21 | qWarning("found"); | ||
20 | popupFactory fact = it.data(); | 22 | popupFactory fact = it.data(); |
21 | return (*fact)(ser, item); | 23 | return (*fact)(ser, item); |
22 | } | 24 | } |
23 | return 0l; | 25 | return 0l; |
24 | } | 26 | } |
25 | void PopupHelper::init() { | 27 | void PopupHelper::init() { |
26 | insert( 1, newRfcComPopup ); | 28 | insert( 1, newRfcComPopup ); |
27 | insert(2, newObexPushPopup ); | 29 | insert(2, newObexPushPopup ); |
28 | } | 30 | } |