summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-04-30 08:54:54 (UTC)
committer korovkin <korovkin>2006-04-30 08:54:54 (UTC)
commit2f32b6d589d389848c5c73ba2e5ad13117c1da9e (patch) (unidiff)
treeec8a086ad17e3fa9014baa9476ab9cc77c5c29dc
parentb91d3399fbd3178085e9d0fc5faeefbe31c674b7 (diff)
downloadopie-2f32b6d589d389848c5c73ba2e5ad13117c1da9e.zip
opie-2f32b6d589d389848c5c73ba2e5ad13117c1da9e.tar.gz
opie-2f32b6d589d389848c5c73ba2e5ad13117c1da9e.tar.bz2
Fixed bug with suspend reenabling.
Made some minor formatting.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/manager/bluebase.cpp39
-rw-r--r--noncore/net/opietooth/manager/obexftpdialog.cpp2
2 files changed, 29 insertions, 12 deletions
diff --git a/noncore/net/opietooth/manager/bluebase.cpp b/noncore/net/opietooth/manager/bluebase.cpp
index 58f97fa..85385d8 100644
--- a/noncore/net/opietooth/manager/bluebase.cpp
+++ b/noncore/net/opietooth/manager/bluebase.cpp
@@ -1,801 +1,818 @@
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 35#ifdef Q_WS_QWS
36#include <qpe/qcopenvelope_qws.h> 36#include <qpe/qcopenvelope_qws.h>
37#endif 37#endif
38 38
39using namespace Opie::Core; 39using namespace Opie::Core;
40 40
41/* QT */ 41/* QT */
42#include <qframe.h> 42#include <qframe.h>
43#include <qlabel.h> 43#include <qlabel.h>
44#include <qpushbutton.h> 44#include <qpushbutton.h>
45#include <qlayout.h> 45#include <qlayout.h>
46#include <qvariant.h> 46#include <qvariant.h>
47#include <qimage.h> 47#include <qimage.h>
48#include <qpixmap.h> 48#include <qpixmap.h>
49#include <qtabwidget.h> 49#include <qtabwidget.h>
50#include <qscrollview.h> 50#include <qscrollview.h>
51#include <qvbox.h> 51#include <qvbox.h>
52#include <qmessagebox.h> 52#include <qmessagebox.h>
53#include <qcombobox.h> 53#include <qcombobox.h>
54#include <qcheckbox.h> 54#include <qcheckbox.h>
55#include <qlineedit.h> 55#include <qlineedit.h>
56#include <qlistview.h> 56#include <qlistview.h>
57#include <qdir.h> 57#include <qdir.h>
58#include <qpopupmenu.h> 58#include <qpopupmenu.h>
59#include <qtimer.h> 59#include <qtimer.h>
60#include <qlist.h> 60#include <qlist.h>
61#include <qfile.h> 61#include <qfile.h>
62 62
63/* STD */ 63/* STD */
64#include <remotedevice.h> 64#include <remotedevice.h>
65#include <services.h> 65#include <services.h>
66#include <stdlib.h> 66#include <stdlib.h>
67 67
68using namespace OpieTooth; 68using namespace OpieTooth;
69//Array of possible speeds of the serial port 69//Array of possible speeds of the serial port
70struct SerSpeed { 70struct SerSpeed {
71 const char* str; //string value 71 const char* str; //string value
72 int val; //value itself 72 int val; //value itself
73} speeds[] = { 73} speeds[] = {
74 { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 }, 74 { "150", B150 }, { "300", B300 }, { "600", B600 }, { "1200", B1200 },
75 { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 }, 75 { "2400", B2400 }, { "4800", B4800 }, { "9600", B9600 },
76 { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 }, 76 { "19200", B19200 }, { "38400", B38400 }, { "57600", B57600 },
77 { "115200", B115200} 77 { "115200", B115200}
78}; 78};
79 79
80BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl ) 80BlueBase::BlueBase( QWidget* parent, const char* name, WFlags fl )
81 : BluetoothBase( parent, name, fl ) 81 : BluetoothBase( parent, name, fl )
82{ 82{
83 m_localDevice = new Manager( "hci0" ); 83 m_localDevice = new Manager( "hci0" );
84 84
85 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) ); 85 connect( PushButton2, SIGNAL( clicked() ), this, SLOT(startScan() ) );
86 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) ); 86 connect( configApplyButton, SIGNAL(clicked() ), this, SLOT(applyConfigChanges() ) );
87 87
88 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) ); 88 connect( rfcommBindButton, SIGNAL( clicked() ), this, SLOT( rfcommDialog() ) );
89 89
90 connect( devicesView, SIGNAL( clicked(QListViewItem*)), 90 connect( devicesView, SIGNAL( clicked(QListViewItem*)),
91 this, SLOT( startServiceActionClicked(QListViewItem*) ) ); 91 this, SLOT( startServiceActionClicked(QListViewItem*) ) );
92 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ), 92 connect( devicesView, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
93 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) ); 93 this, SLOT(startServiceActionHold(QListViewItem*,const QPoint&,int) ) );
94 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ), 94 connect( m_localDevice , SIGNAL( foundServices(const QString&,Services::ValueList) ),
95 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) ); 95 this, SLOT( addServicesToDevice(const QString&,Services::ValueList) ) );
96 connect( m_localDevice, SIGNAL( available(const QString&,bool) ), 96 connect( m_localDevice, SIGNAL( available(const QString&,bool) ),
97 this, SLOT( deviceActive(const QString&,bool) ) ); 97 this, SLOT( deviceActive(const QString&,bool) ) );
98 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ), 98 connect( m_localDevice, SIGNAL( connections(ConnectionState::ValueList) ),
99 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) ); 99 this, SLOT( addConnectedDevices(ConnectionState::ValueList) ) );
100 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ), 100 connect( m_localDevice, SIGNAL( signalStrength(const QString&,const QString&) ),
101 this, SLOT( addSignalStrength(const QString&,const QString&) ) ); 101 this, SLOT( addSignalStrength(const QString&,const QString&) ) );
102 connect(runButton, SIGNAL(clicked()), this, SLOT(doForward())); 102 connect(runButton, SIGNAL(clicked()), this, SLOT(doForward()));
103 connect(encCheckBox, SIGNAL(toggled(bool)), this, SLOT(doEncrypt(bool))); 103 connect(encCheckBox, SIGNAL(toggled(bool)), this, SLOT(doEncrypt(bool)));
104 connect(servicesEditButton, SIGNAL(clicked()), this, SLOT(editServices())); 104 connect(servicesEditButton, SIGNAL(clicked()), this, SLOT(editServices()));
105 105
106 // let hold be rightButtonClicked() 106 // let hold be rightButtonClicked()
107 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold); 107 QPEApplication::setStylusOperation( devicesView->viewport(), QPEApplication::RightOnHold);
108 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold); 108 QPEApplication::setStylusOperation( connectionsView->viewport(), QPEApplication::RightOnHold);
109 109
110 //Load all icons needed 110 //Load all icons needed
111 m_offPix = Resource::loadPixmap( "opietooth/notconnected" ); 111 m_offPix = Resource::loadPixmap( "opietooth/notconnected" );
112 m_onPix = Resource::loadPixmap( "opietooth/connected" ); 112 m_onPix = Resource::loadPixmap( "opietooth/connected" );
113 m_findPix = Resource::loadPixmap( "opietooth/find" ); 113 m_findPix = Resource::loadPixmap( "opietooth/find" );
114 114
115 QPalette pal = this->palette(); 115 QPalette pal = this->palette();
116 QColor col = pal.color( QPalette::Active, QColorGroup::Background ); 116 QColor col = pal.color( QPalette::Active, QColorGroup::Background );
117 pal.setColor( QPalette::Active, QColorGroup::Button, col ); 117 pal.setColor( QPalette::Active, QColorGroup::Button, col );
118 pal.setColor( QPalette::Inactive, QColorGroup::Button, col ); 118 pal.setColor( QPalette::Inactive, QColorGroup::Button, col );
119 pal.setColor( QPalette::Normal, QColorGroup::Button, col ); 119 pal.setColor( QPalette::Normal, QColorGroup::Button, col );
120 pal.setColor( QPalette::Disabled, QColorGroup::Button, col ); 120 pal.setColor( QPalette::Disabled, QColorGroup::Button, col );
121 this->setPalette( pal ); 121 this->setPalette( pal );
122 122
123 setCaption( tr( "Bluetooth Manager" ) ); 123 setCaption( tr( "Bluetooth Manager" ) );
124 124
125 readConfig(); 125 readConfig();
126 initGui(); 126 initGui();
127 127
128 devicesView->setRootIsDecorated(true); 128 devicesView->setRootIsDecorated(true);
129 m_iconLoader = new BTIconLoader(); 129 m_iconLoader = new BTIconLoader();
130 writeToHciConfig(); 130 writeToHciConfig();
131 addConnectedDevices(); 131 addConnectedDevices();
132 readSavedDevices(); 132 readSavedDevices();
133 addServicesToDevices(); 133 addServicesToDevices();
134 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) ); 134 QTimer::singleShot( 3000, this, SLOT( addServicesToDevices() ) );
135 forwarder = NULL; 135 forwarder = NULL;
136} 136}
137 137
138/** 138/**
139 * Reads all options from the config file 139 * Reads all options from the config file
140 */ 140 */
141void BlueBase::readConfig() 141void BlueBase::readConfig()
142{ 142{
143 143
144 Config cfg( "bluetoothmanager" ); 144 Config cfg( "bluetoothmanager" );
145 cfg.setGroup( "bluezsettings" ); 145 cfg.setGroup( "bluezsettings" );
146 146
147 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
148 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
149 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE ); 149 m_useEncryption = cfg.readBoolEntry( "useEncryption" , TRUE );
150 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE ); 150 m_enableAuthentification = cfg.readBoolEntry( "enableAuthentification" , TRUE );
151 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE ); 151 m_enablePagescan = cfg.readBoolEntry( "enablePagescan" , TRUE );
152 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE ); 152 m_enableInquiryscan = cfg.readBoolEntry( "enableInquiryscan" , TRUE );
153} 153}
154 154
155/** 155/**
156 * Writes all options to the config file 156 * Writes all options to the config file
157 */ 157 */
158void BlueBase::writeConfig() 158void BlueBase::writeConfig()
159{ 159{
160 160
161 Config cfg( "bluetoothmanager" ); 161 Config cfg( "bluetoothmanager" );
162 cfg.setGroup( "bluezsettings" ); 162 cfg.setGroup( "bluezsettings" );
163 163
164 cfg.writeEntry( "name" , m_deviceName ); 164 cfg.writeEntry( "name" , m_deviceName );
165 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey ); 165 cfg.writeEntryCrypt( "passkey" , m_defaultPasskey );
166 cfg.writeEntry( "useEncryption" , m_useEncryption ); 166 cfg.writeEntry( "useEncryption" , m_useEncryption );
167 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification ); 167 cfg.writeEntry( "enableAuthentification" , m_enableAuthentification );
168 cfg.writeEntry( "enablePagescan" , m_enablePagescan ); 168 cfg.writeEntry( "enablePagescan" , m_enablePagescan );
169 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan ); 169 cfg.writeEntry( "enableInquiryscan" , m_enableInquiryscan );
170 170
171 writeToHciConfig(); 171 writeToHciConfig();
172} 172}
173 173
174/** 174/**
175 * Modify the hcid.conf file to our needs 175 * Modify the hcid.conf file to our needs
176 */ 176 */
177void BlueBase::writeToHciConfig() 177void BlueBase::writeToHciConfig()
178{ 178{
179 QFile pinFile("/etc/bluetooth/pin"); // /etc/bluetooth/pin file 179 QFile pinFile("/etc/bluetooth/pin"); // /etc/bluetooth/pin file
180 owarn << "writeToHciConfig" << oendl; 180 owarn << "writeToHciConfig" << oendl;
181 //Write /etc/bluetooth/hcid.conf file 181 //Write /etc/bluetooth/hcid.conf file
182 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" ); 182 HciConfWrapper hciconf ( "/etc/bluetooth/hcid.conf" );
183 hciconf.load(); 183 hciconf.load();
184 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" ); 184 hciconf.setPinHelper( QPEApplication::qpeDir() + "bin/bluepin" );
185 hciconf.setName( m_deviceName ); 185 hciconf.setName( m_deviceName );
186 hciconf.setEncrypt( m_useEncryption ); 186 hciconf.setEncrypt( m_useEncryption );
187 hciconf.setAuth( m_enableAuthentification ); 187 hciconf.setAuth( m_enableAuthentification );
188 hciconf.setPscan( m_enablePagescan ); 188 hciconf.setPscan( m_enablePagescan );
189 hciconf.setIscan( m_enableInquiryscan ); 189 hciconf.setIscan( m_enableInquiryscan );
190 hciconf.save(); 190 hciconf.save();
191 // Write /etc/bluetooth/pin (default PIN file) 191 // Write /etc/bluetooth/pin (default PIN file)
192 pinFile.open(IO_WriteOnly | IO_Truncate); 192 pinFile.open(IO_WriteOnly | IO_Truncate);
193 pinFile.writeBlock(m_defaultPasskey, m_defaultPasskey.length()); 193 pinFile.writeBlock(m_defaultPasskey, m_defaultPasskey.length());
194 pinFile.writeBlock("\n", sizeof("\n")); 194 pinFile.writeBlock("\n", sizeof("\n"));
195 pinFile.flush(); 195 pinFile.flush();
196 pinFile.close(); 196 pinFile.close();
197} 197}
198 198
199 199
200/** 200/**
201 * Read the list of already known devices 201 * Read the list of already known devices
202 */ 202 */
203void BlueBase::readSavedDevices() 203void BlueBase::readSavedDevices()
204{ 204{
205 205
206 QValueList<RemoteDevice> loadedDevices; 206 QValueList<RemoteDevice> loadedDevices;
207 DeviceHandler handler; 207 DeviceHandler handler;
208 loadedDevices = handler.load(); 208 loadedDevices = handler.load();
209 209
210 addSearchedDevices( loadedDevices ); 210 addSearchedDevices( loadedDevices );
211} 211}
212 212
213 213
214/** 214/**
215 * Write the list of already known devices 215 * Write the list of already known devices
216 */ 216 */
217void BlueBase::writeSavedDevices() 217void BlueBase::writeSavedDevices()
218{ 218{
219 QListViewItemIterator it( devicesView ); 219 QListViewItemIterator it( devicesView );
220 BTListItem* item; 220 BTListItem* item;
221 BTDeviceItem* device; 221 BTDeviceItem* device;
222 RemoteDevice::ValueList list; 222 RemoteDevice::ValueList list;
223 for ( ; it.current(); ++it ) 223 for ( ; it.current(); ++it )
224 { 224 {
225 item = (BTListItem*)it.current(); 225 item = (BTListItem*)it.current();
226 if(item->typeId() != BTListItem::Device ) 226 if(item->typeId() != BTListItem::Device )
227 continue; 227 continue;
228 device = (BTDeviceItem*)item; 228 device = (BTDeviceItem*)item;
229 229
230 list.append( device->remoteDevice() ); 230 list.append( device->remoteDevice() );
231 } 231 }
232 /* 232 /*
233 * if not empty save the List through DeviceHandler 233 * if not empty save the List through DeviceHandler
234 */ 234 */
235 if ( list.isEmpty() ) 235 if ( list.isEmpty() )
236 return; 236 return;
237 DeviceHandler handler; 237 DeviceHandler handler;
238 handler.save( list ); 238 handler.save( list );
239} 239}
240 240
241 241
242/** 242/**
243 * Set up the gui 243 * Set up the gui
244 */ 244 */
245void BlueBase::initGui() 245void BlueBase::initGui()
246{ 246{
247 StatusLabel->setText( status() ); // maybe move it to getStatus() 247 StatusLabel->setText( status() ); // maybe move it to getStatus()
248 cryptCheckBox->setChecked( m_useEncryption ); 248 cryptCheckBox->setChecked( m_useEncryption );
249 authCheckBox->setChecked( m_enableAuthentification ); 249 authCheckBox->setChecked( m_enableAuthentification );
250 pagescanCheckBox->setChecked( m_enablePagescan ); 250 pagescanCheckBox->setChecked( m_enablePagescan );
251 inquiryscanCheckBox->setChecked( m_enableInquiryscan ); 251 inquiryscanCheckBox->setChecked( m_enableInquiryscan );
252 deviceNameLine->setText( m_deviceName ); 252 deviceNameLine->setText( m_deviceName );
253 passkeyLine->setText( m_defaultPasskey ); 253 passkeyLine->setText( m_defaultPasskey );
254 // set info tab 254 // set info tab
255 setInfo(); 255 setInfo();
256 serDevName->setText(tr("/dev/ircomm0")); 256 serDevName->setText(tr("/dev/ircomm0"));
257 for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) { 257 for (unsigned int i = 0; i < (sizeof(speeds) / sizeof(speeds[0])); i++) {
258 serSpeed->insertItem(speeds[i].str); 258 serSpeed->insertItem(speeds[i].str);
259 } 259 }
260 serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1); 260 serSpeed->setCurrentItem((sizeof(speeds) / sizeof(speeds[0])) - 1);
261 encCheckBox->setChecked(true); 261 encCheckBox->setChecked(true);
262} 262}
263 263
264 264
265/** 265/**
266 * Get the status informations and returns it 266 * Get the status informations and returns it
267 * @return QString the status informations gathered 267 * @return QString the status informations gathered
268 */ 268 */
269QString BlueBase::status()const 269QString BlueBase::status()const
270{ 270{
271 QString infoString = tr( "<b>Device name : </b> Ipaq" ); 271 QString infoString = tr( "<b>Device name : </b> Ipaq" );
272 infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" ); 272 infoString += QString( "<br><b>" + tr( "MAC adress: " ) +"</b> No idea" );
273 infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" ); 273 infoString += QString( "<br><b>" + tr( "Class" ) + "</b> PDA" );
274 274
275 return (infoString); 275 return (infoString);
276} 276}
277 277
278 278
279/** 279/**
280 * Read the current values from the gui and invoke writeConfig() 280 * Read the current values from the gui and invoke writeConfig()
281 */ 281 */
282void BlueBase::applyConfigChanges() 282void BlueBase::applyConfigChanges()
283{ 283{
284 m_deviceName = deviceNameLine->text(); 284 m_deviceName = deviceNameLine->text();
285 m_defaultPasskey = passkeyLine->text(); 285 m_defaultPasskey = passkeyLine->text();
286 m_useEncryption = cryptCheckBox->isChecked(); 286 m_useEncryption = cryptCheckBox->isChecked();
287 m_enableAuthentification = authCheckBox->isChecked(); 287 m_enableAuthentification = authCheckBox->isChecked();
288 m_enablePagescan = pagescanCheckBox->isChecked(); 288 m_enablePagescan = pagescanCheckBox->isChecked();
289 m_enableInquiryscan = inquiryscanCheckBox->isChecked(); 289 m_enableInquiryscan = inquiryscanCheckBox->isChecked();
290 290
291 writeConfig(); 291 writeConfig();
292 292
293 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") ); 293 QMessageBox::information( this, tr("Test") , tr("Changes were applied.") );
294} 294}
295 295
296/** 296/**
297 * Launch Rfcomm Bind dialog 297 * Launch Rfcomm Bind dialog
298 * 298 *
299 */ 299 */
300void BlueBase::rfcommDialog() 300void BlueBase::rfcommDialog()
301{ 301{
302 RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp ); 302 RfcommAssignDialog rfcommAssign ( this, "RfcommAssignDialog", true, WStyle_ContextHelp );
303 303
304 if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted ) 304 if ( QPEApplication::execDialog( &rfcommAssign ) == QDialog::Accepted )
305 { 305 {
306 rfcommAssign.saveConfig(); 306 rfcommAssign.saveConfig();
307 } 307 }
308} 308}
309 309
310/** 310/**
311 * Add fresh found devices from scan dialog to the listing 311 * Add fresh found devices from scan dialog to the listing
312 * 312 *
313 */ 313 */
314void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices ) 314void BlueBase::addSearchedDevices( const QValueList<RemoteDevice> &newDevices )
315{ 315{
316 BTDeviceItem * deviceItem; 316 BTDeviceItem * deviceItem;
317 QValueList<RemoteDevice>::ConstIterator it; 317 QValueList<RemoteDevice>::ConstIterator it;
318 318
319 for( it = newDevices.begin(); it != newDevices.end() ; ++it ) 319 for( it = newDevices.begin(); it != newDevices.end() ; ++it )
320 { 320 {
321 321
322 if (find( (*it) )) // is already inserted 322 if (find( (*it) )) // is already inserted
323 continue; 323 continue;
324 324
325 deviceItem = new BTDeviceItem( devicesView , (*it) ); 325 deviceItem = new BTDeviceItem( devicesView , (*it) );
326 deviceItem->setPixmap( 1, m_findPix ); 326 deviceItem->setPixmap( 1, m_findPix );
327 deviceItem->setExpandable ( true ); 327 deviceItem->setExpandable ( true );
328 328
329 // look if device is avail. atm, async 329 // look if device is avail. atm, async
330 deviceActive( (*it) ); 330 deviceActive( (*it) );
331 } 331 }
332} 332}
333 333
334 334
335/** 335/**
336 * Action that is toggled on entrys on click 336 * Action that is toggled on entrys on click
337 */ 337 */
338void BlueBase::startServiceActionClicked( QListViewItem */*item*/ ) 338void BlueBase::startServiceActionClicked( QListViewItem */*item*/ )
339{} 339{}
340 340
341 341
342/** 342/**
343 * Action that are toggled on hold (mostly QPopups i guess) 343 * Action that are toggled on hold (mostly QPopups i guess)
344 */ 344 */
345void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ ) 345void BlueBase::startServiceActionHold( QListViewItem * item, const QPoint & point, int /*column*/ )
346{ 346{
347 if (!item ) 347 if (!item )
348 return; 348 return;
349 349
350 QPopupMenu *menu = new QPopupMenu(); 350 QPopupMenu *menu = new QPopupMenu();
351 351
352 if ( static_cast<BTListItem*>( item )->type() == "device") 352 if ( static_cast<BTListItem*>( item )->type() == "device")
353 { 353 {
354 QPopupMenu *groups = new QPopupMenu(); 354 QPopupMenu *groups = new QPopupMenu();
355 355
356 menu->insertItem( static_cast<BTDeviceItem*>( item )->name(), 0 ); 356 menu->insertItem( static_cast<BTDeviceItem*>( item )->name(), 0 );
357 menu->insertSeparator( 1 ); 357 menu->insertSeparator( 1 );
358 menu->insertItem( tr( "&Rescan services" ), 2); 358 menu->insertItem( tr( "&Rescan services" ), 2);
359 // menu->insertItem( tr( "&Add to group" ), groups, 3); 359 // menu->insertItem( tr( "&Add to group" ), groups, 3);
360 menu->insertItem( tr( "&Delete"), 4); 360 menu->insertItem( tr( "&Delete"), 4);
361 int ret = menu->exec( point, 0); 361 int ret = menu->exec( point, 0);
362 362
363 switch(ret) 363 switch(ret)
364 { 364 {
365 case -1: 365 case -1:
366 break; 366 break;
367 case 2: 367 case 2:
368 addServicesToDevice( static_cast<BTDeviceItem*>( item ) ); 368 addServicesToDevice( static_cast<BTDeviceItem*>( item ) );
369 break; 369 break;
370 370
371 case 4: 371 case 4:
372 // deletes childs too 372 // deletes childs too
373 delete item; 373 delete item;
374 break; 374 break;
375 } 375 }
376 // delete groups; 376 // delete groups;
377 } 377 }
378 378
379 /* 379 /*
380 * We got service sensitive PopupMenus in our factory 380 * We got service sensitive PopupMenus in our factory
381 * We will create one through the factory and will insert 381 * We will create one through the factory and will insert
382 * our Separator + ShowInfo into the menu or create a new 382 * our Separator + ShowInfo into the menu or create a new
383 * one if the factory returns 0 383 * one if the factory returns 0
384 * PopupMenu deletion is kind of weird. 384 * PopupMenu deletion is kind of weird.
385 * If escaped( -1 ) or any of our items were chosen we'll 385 * If escaped( -1 ) or any of our items were chosen we'll
386 * delete the PopupMenu otherwise it's the responsibility of 386 * delete the PopupMenu otherwise it's the responsibility of
387 * the PopupMenu to delete itself 387 * the PopupMenu to delete itself
388 * 388 *
389 */ 389 */
390 else if ( ((BTListItem*)item)->type() == "service") 390 else if ( ((BTListItem*)item)->type() == "service")
391 { 391 {
392 BTServiceItem* service = (BTServiceItem*)item; 392 BTServiceItem* service = (BTServiceItem*)item;
393 QMap<int, QString> list = service->services().classIdList(); 393 QMap<int, QString> list = service->services().classIdList();
394 QMap<int, QString>::Iterator it = list.begin(); 394 QMap<int, QString>::Iterator it = list.begin();
395 QPopupMenu *popup =0l; 395 QPopupMenu *popup =0l;
396 if ( it != list.end() ) 396 if ( it != list.end() )
397 { 397 {
398 owarn << "Searching id " << it.key() << " " << it.data().latin1() << "" << oendl; 398 owarn << "Searching id " << it.key() << " " << it.data().latin1() << "" << oendl;
399 popup = m_popHelper.find( it.key(), 399 popup = m_popHelper.find( it.key(),
400 service->services(), 400 service->services(),
401 (BTDeviceItem*)service->parent() ); 401 (BTDeviceItem*)service->parent() );
402 } 402 }
403 else 403 else
404 { 404 {
405 owarn << "Empty" << oendl; 405 owarn << "Empty" << oendl;
406 } 406 }
407 407
408 if ( popup == 0l ) 408 if ( popup == 0l )
409 { 409 {
410 owarn << "factory returned 0l" << oendl; 410 owarn << "factory returned 0l" << oendl;
411 popup = new QPopupMenu(); 411 popup = new QPopupMenu();
412 } 412 }
413 int test1 = popup->insertItem( tr("Test1:"), 2); 413 int test1 = popup->insertItem( tr("Test1:"), 2);
414 414
415 int ret = popup->exec( point ); 415 int ret = popup->exec( point );
416 owarn << "returned from exec() " << oendl; 416 owarn << "returned from exec() " << oendl;
417 if ( ret == -1 ) 417 if ( ret == -1 )
418 { 418 {
419 ; 419 ;
420 } 420 }
421 else if ( ret == test1 ) 421 else if ( ret == test1 )
422 { 422 {
423 ; 423 ;
424 } 424 }
425 delete popup; 425 delete popup;
426 } 426 }
427 delete menu; 427 delete menu;
428} 428}
429 429
430 430
431void BlueBase::addServicesToDevices() 431void BlueBase::addServicesToDevices()
432{ 432{
433 odebug << "BlueBase::addServicesToDevices()" << oendl; 433 odebug << "BlueBase::addServicesToDevices()" << oendl;
434 BTDeviceItem* item = (BTDeviceItem*) devicesView->firstChild(); 434 BTDeviceItem* item = (BTDeviceItem*) devicesView->firstChild();
435 while ( item ) 435 while ( item )
436 { 436 {
437 addServicesToDevice( item ); 437 addServicesToDevice( item );
438 item = (BTDeviceItem*) static_cast<QListViewItem*>( item )->nextSibling(); 438 item = (BTDeviceItem*) static_cast<QListViewItem*>( item )->nextSibling();
439 } 439 }
440} 440}
441 441
442/** 442/**
443 * Search and display avail. services for a device (on expand from device listing) 443 * Search and display avail. services for a device (on expand from device listing)
444 * @param item the service item returned 444 * @param item the service item returned
445 */ 445 */
446void BlueBase::addServicesToDevice( BTDeviceItem * item ) 446void BlueBase::addServicesToDevice( BTDeviceItem * item )
447{ 447{
448 odebug << "BlueBase::addServicesToDevice" << oendl; 448 odebug << "BlueBase::addServicesToDevice" << oendl;
449 // row of mac adress text(3) 449 // row of mac adress text(3)
450 RemoteDevice device = item->remoteDevice(); 450 RemoteDevice device = item->remoteDevice();
451 m_deviceList.insert( item->mac() , item ); 451 m_deviceList.insert( item->mac() , item );
452 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back 452 // and some time later I get a signal foundServices( const QString& device, Services::ValueList ); back
453 m_localDevice->searchServices( device ); 453 m_localDevice->searchServices( device );
454} 454}
455 455
456 456
457/** 457/**
458 * @param device the mac address of the remote device 458 * @param device the mac address of the remote device
459 * @param servicesList the list with the service the device has. 459 * @param servicesList the list with the service the device has.
460 */ 460 */
461void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList ) 461void BlueBase::addServicesToDevice( const QString& device, Services::ValueList servicesList )
462{ 462{
463 odebug << "BlueBase::fill services list" << oendl; 463 odebug << "BlueBase::fill services list" << oendl;
464 464
465 QMap<QString,BTDeviceItem*>::Iterator it; 465 QMap<QString,BTDeviceItem*>::Iterator it;
466 BTDeviceItem* deviceItem = 0; 466 BTDeviceItem* deviceItem = 0;
467 467
468 // get the right devices which requested the search 468 // get the right devices which requested the search
469 it = m_deviceList.find( device ); 469 it = m_deviceList.find( device );
470 if( it == m_deviceList.end() ) 470 if( it == m_deviceList.end() )
471 return; 471 return;
472 deviceItem = it.data(); 472 deviceItem = it.data();
473 473
474 // remove previous entries 474 // remove previous entries
475 QList<QListViewItem> tempList; 475 QList<QListViewItem> tempList;
476 tempList.setAutoDelete( true ); 476 tempList.setAutoDelete( true );
477 QListViewItem * child = deviceItem->firstChild(); 477 QListViewItem * child = deviceItem->firstChild();
478 while( child ) 478 while( child )
479 { 479 {
480 tempList.append( child ); 480 tempList.append( child );
481 child = child->nextSibling(); 481 child = child->nextSibling();
482 } 482 }
483 tempList.clear(); 483 tempList.clear();
484 484
485 QValueList<OpieTooth::Services>::Iterator it2; 485 QValueList<OpieTooth::Services>::Iterator it2;
486 BTServiceItem* serviceItem; 486 BTServiceItem* serviceItem;
487 487
488 488
489 if (!servicesList.isEmpty() ) 489 if (!servicesList.isEmpty() )
490 { 490 {
491 // add services 491 // add services
492 QMap<int, QString> list; 492 QMap<int, QString> list;
493 QMap<int, QString>::Iterator classIt; 493 QMap<int, QString>::Iterator classIt;
494 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 ) 494 for( it2 = servicesList.begin(); it2 != servicesList.end(); ++it2 )
495 { 495 {
496 serviceItem = new BTServiceItem( deviceItem, (*it2) ); 496 serviceItem = new BTServiceItem( deviceItem, (*it2) );
497 list = (*it2).classIdList(); 497 list = (*it2).classIdList();
498 classIt = list.begin(); 498 classIt = list.begin();
499 int classId=0; 499 int classId=0;
500 if ( classIt != list.end() ) 500 if ( classIt != list.end() )
501 { 501 {
502 classId = classIt.key(); 502 classId = classIt.key();
503 } 503 }
504 504
505 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) ); 505 serviceItem->setPixmap( 0, m_iconLoader->serviceIcon( classId ) );
506 } 506 }
507 } 507 }
508 else 508 else
509 { 509 {
510 Services s1; 510 Services s1;
511 s1.setServiceName( tr("no services found") ); 511 s1.setServiceName( tr("no services found") );
512 serviceItem = new BTServiceItem( deviceItem, s1 ); 512 serviceItem = new BTServiceItem( deviceItem, s1 );
513 } 513 }
514 // now remove them from the list 514 // now remove them from the list
515 m_deviceList.remove( it ); 515 m_deviceList.remove( it );
516} 516}
517 517
518void BlueBase::addSignalStrength() 518void BlueBase::addSignalStrength()
519{ 519{
520 520
521 QListViewItemIterator it( connectionsView ); 521 QListViewItemIterator it( connectionsView );
522 for ( ; it.current(); ++it ) 522 for ( ; it.current(); ++it )
523 { 523 {
524 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() ); 524 m_localDevice->signalStrength( ((BTConnectionItem*)it.current() )->connection().mac() );
525 } 525 }
526 526
527 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); 527 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) );
528} 528}
529 529
530void BlueBase::addSignalStrength( const QString& mac, const QString& strength ) 530void BlueBase::addSignalStrength( const QString& mac, const QString& strength )
531{ 531{
532 532
533 QListViewItemIterator it( connectionsView ); 533 QListViewItemIterator it( connectionsView );
534 for ( ; it.current(); ++it ) 534 for ( ; it.current(); ++it )
535 { 535 {
536 if( ((BTConnectionItem*)it.current())->connection().mac() == mac ) 536 if( ((BTConnectionItem*)it.current())->connection().mac() == mac )
537 { 537 {
538 ((BTConnectionItem*)it.current() )->setSignalStrength( strength ); 538 ((BTConnectionItem*)it.current() )->setSignalStrength( strength );
539 } 539 }
540 } 540 }
541} 541}
542 542
543/** 543/**
544 * Add the existing connections (pairs) to the connections tab. 544 * Add the existing connections (pairs) to the connections tab.
545 * This one triggers the search 545 * This one triggers the search
546 */ 546 */
547void BlueBase::addConnectedDevices() 547void BlueBase::addConnectedDevices()
548{ 548{
549 m_localDevice->searchConnections(); 549 m_localDevice->searchConnections();
550 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) ); 550 QTimer::singleShot( 5000, this, SLOT( addSignalStrength() ) );
551} 551}
552 552
553/** 553/**
554 * This adds the found connections to the connection tab. 554 * This adds the found connections to the connection tab.
555 * @param connectionList the ValueList with all current connections 555 * @param connectionList the ValueList with all current connections
556 */ 556 */
557void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList ) 557void BlueBase::addConnectedDevices( ConnectionState::ValueList connectionList )
558{ 558{
559 559
560 QValueList<OpieTooth::ConnectionState>::Iterator it; 560 QValueList<OpieTooth::ConnectionState>::Iterator it;
561 BTConnectionItem * connectionItem; 561 BTConnectionItem * connectionItem;
562 562
563 if ( !connectionList.isEmpty() ) 563 if ( !connectionList.isEmpty() )
564 { 564 {
565 565
566 for (it = connectionList.begin(); it != connectionList.end(); ++it) 566 for (it = connectionList.begin(); it != connectionList.end(); ++it)
567 { 567 {
568 568
569 QListViewItemIterator it2( connectionsView ); 569 QListViewItemIterator it2( connectionsView );
570 bool found = false; 570 bool found = false;
571 for ( ; it2.current(); ++it2 ) 571 for ( ; it2.current(); ++it2 )
572 { 572 {
573 if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() ) 573 if( ( (BTConnectionItem*)it2.current())->connection().mac() == (*it).mac() )
574 { 574 {
575 found = true; 575 found = true;
576 } 576 }
577 } 577 }
578 578
579 if ( found == false ) 579 if ( found == false )
580 { 580 {
581 connectionItem = new BTConnectionItem( connectionsView, (*it) ); 581 connectionItem = new BTConnectionItem( connectionsView, (*it) );
582 582
583 if( m_deviceList.find((*it).mac()).data() ) 583 if( m_deviceList.find((*it).mac()).data() )
584 { 584 {
585 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() ); 585 connectionItem->setName( m_deviceList.find( (*it).mac()).data()->name() );
586 } 586 }
587 } 587 }
588 588
589 } 589 }
590 590
591 QListViewItemIterator it2( connectionsView ); 591 QListViewItemIterator it2( connectionsView );
592 for ( ; it2.current(); ++it2 ) 592 for ( ; it2.current(); ++it2 )
593 { 593 {
594 bool found = false; 594 bool found = false;
595 for (it = connectionList.begin(); it != connectionList.end(); ++it) 595 for (it = connectionList.begin(); it != connectionList.end(); ++it)
596 { 596 {
597 if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() ) 597 if( ( ((BTConnectionItem*)it2.current())->connection().mac() ) == (*it).mac() )
598 { 598 {
599 found = true; 599 found = true;
600 } 600 }
601 } 601 }
602 602
603 if ( !found ) 603 if ( !found )
604 { 604 {
605 delete it2.current(); 605 delete it2.current();
606 } 606 }
607 607
608 } 608 }
609 609
610 610
611 } 611 }
612 else 612 else
613 { 613 {
614 connectionsView->clear(); 614 connectionsView->clear();
615 ConnectionState con; 615 ConnectionState con;
616 con.setMac( tr("No connections found") ); 616 con.setMac( tr("No connections found") );
617 connectionItem = new BTConnectionItem( connectionsView , con ); 617 connectionItem = new BTConnectionItem( connectionsView , con );
618 } 618 }
619 619
620 // recall connection search after some time 620 // recall connection search after some time
621 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) ); 621 QTimer::singleShot( 15000, this, SLOT( addConnectedDevices() ) );
622} 622}
623 623
624 624
625/** 625/**
626 * Find out if a device can currently be reached 626 * Find out if a device can currently be reached
627 * @param device 627 * @param device
628 */ 628 */
629void BlueBase::deviceActive( const RemoteDevice &device ) 629void BlueBase::deviceActive( const RemoteDevice &device )
630{ 630{
631 // search by mac, async, gets a signal back 631 // search by mac, async, gets a signal back
632 // 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
633 m_localDevice->isAvailable( device.mac() ); 633 m_localDevice->isAvailable( device.mac() );
634} 634}
635 635
636 636
637/** 637/**
638 * The signal catcher. Set the avail. status on device. 638 * The signal catcher. Set the avail. status on device.
639 * @param device - the mac address 639 * @param device - the mac address
640 * @param connected - if it is avail. or not 640 * @param connected - if it is avail. or not
641 */ 641 */
642void BlueBase::deviceActive( const QString& device, bool connected ) 642void BlueBase::deviceActive( const QString& device, bool connected )
643{ 643{
644 odebug << "deviceActive slot" << oendl; 644 odebug << "deviceActive slot" << oendl;
645 645
646 QMap<QString,BTDeviceItem*>::Iterator it; 646 QMap<QString,BTDeviceItem*>::Iterator it;
647 647
648 it = m_deviceList.find( device ); 648 it = m_deviceList.find( device );
649 if( it == m_deviceList.end() ) 649 if( it == m_deviceList.end() )
650 return; 650 return;
651 651
652 BTDeviceItem* deviceItem = it.data(); 652 BTDeviceItem* deviceItem = it.data();
653 653
654 if ( connected ) 654 if ( connected )
655 { 655 {
656 deviceItem->setPixmap( 1, m_onPix ); 656 deviceItem->setPixmap( 1, m_onPix );
657 } 657 }
658 else 658 else
659 { 659 {
660 deviceItem->setPixmap( 1, m_offPix ); 660 deviceItem->setPixmap( 1, m_offPix );
661 } 661 }
662 m_deviceList.remove( it ); 662 m_deviceList.remove( it );
663} 663}
664 664
665 665
666/** 666/**
667 * Open the "scan for devices" dialog 667 * Open the "scan for devices" dialog
668 */ 668 */
669void BlueBase::startScan() 669void BlueBase::startScan()
670{ 670{
671 ScanDialog *scan = new ScanDialog( this, "ScanDialog", 671 ScanDialog *scan = new ScanDialog( this, "ScanDialog",
672 true, WDestructiveClose ); 672 true, WDestructiveClose );
673 QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ), 673 QObject::connect( scan, SIGNAL( selectedDevices(const QValueList<RemoteDevice>&) ),
674 this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) ); 674 this, SLOT( addSearchedDevices(const QValueList<RemoteDevice>&) ) );
675 675
676 QPEApplication::showDialog( scan ); 676 QPEApplication::showDialog( scan );
677} 677}
678 678
679 679
680/** 680/**
681 * Set the informations about the local device in information Tab 681 * Set the informations about the local device in information Tab
682 */ 682 */
683void BlueBase::setInfo() 683void BlueBase::setInfo()
684{ 684{
685 StatusLabel->setText( status() ); 685 StatusLabel->setText( status() );
686} 686}
687 687
688 688
689/** 689/**
690 * Decontructor 690 * Decontructor
691 */ 691 */
692BlueBase::~BlueBase() 692BlueBase::~BlueBase()
693{ 693{
694 writeSavedDevices(); 694 writeSavedDevices();
695 if (forwarder) { 695 if (forwarder) {
696#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 696#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
697 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 697 {
698 << QPEApplication::Enable; 698 odebug << "SUSP: Enable suspend mode" << oendl;
699 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
700 e << QPEApplication::Enable;
701 }
699#endif 702#endif
700 delete forwarder; 703 delete forwarder;
701 forwarder = NULL; 704 forwarder = NULL;
702 } 705 }
703 delete m_iconLoader; 706 delete m_iconLoader;
704} 707}
705 708
706 709
707/** 710/**
708 * find searches the ListView for a BTDeviceItem containig 711 * find searches the ListView for a BTDeviceItem containig
709 * the same Device if found return true else false 712 * the same Device if found return true else false
710 * @param dev RemoteDevice to find 713 * @param dev RemoteDevice to find
711 * @return returns true if found 714 * @return returns true if found
712 */ 715 */
713bool BlueBase::find( const RemoteDevice& rem ) 716bool BlueBase::find( const RemoteDevice& rem )
714{ 717{
715 QListViewItemIterator it( devicesView ); 718 QListViewItemIterator it( devicesView );
716 BTListItem* item; 719 BTListItem* item;
717 BTDeviceItem* device; 720 BTDeviceItem* device;
718 for (; it.current(); ++it ) 721 for (; it.current(); ++it )
719 { 722 {
720 item = (BTListItem*) it.current(); 723 item = (BTListItem*) it.current();
721 if ( item->typeId() != BTListItem::Device ) 724 if ( item->typeId() != BTListItem::Device )
722 continue; 725 continue;
723 726
724 device = (BTDeviceItem*)item; 727 device = (BTDeviceItem*)item;
725 if ( rem.equals( device->remoteDevice() ) ) 728 if ( rem.equals( device->remoteDevice() ) )
726 return true; 729 return true;
727 } 730 }
728 return false; // not found 731 return false; // not found
729} 732}
730 733
731/** 734/**
732 * Start process of the cell phone forwarding 735 * Start process of the cell phone forwarding
733 */ 736 */
734void BlueBase::doForward() 737void BlueBase::doForward()
735{ 738{
736 if (forwarder && forwarder->isRunning()) { 739 if (forwarder && forwarder->isRunning()) {
737 runButton->setText("start gateway"); 740 runButton->setText("start gateway");
738 forwarder->stop(); 741 forwarder->stop();
739 delete forwarder; 742 delete forwarder;
740 forwarder = NULL; 743 forwarder = NULL;
744#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
745 {
746 odebug << "SUSP: Enable suspend mode" << oendl;
747 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
748 e << QPEApplication::Enable;
749 }
750#endif
741 return; 751 return;
742 } 752 }
743 QString str = serDevName->text(); 753 QString str = serDevName->text();
744 forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val); 754 forwarder = new SerialForwarder(str, speeds[serSpeed->currentItem()].val);
745 connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)),
746 this, SLOT(forwardExited(Opie::Core::OProcess*)));
747 if (forwarder->start(OProcess::NotifyOnExit) < 0) { 755 if (forwarder->start(OProcess::NotifyOnExit) < 0) {
748 QMessageBox::critical(this, tr("Forwarder Error"), 756 QMessageBox::critical(this, tr("Forwarder Error"),
749 tr("Forwarder start error:") + tr(strerror(errno))); 757 tr("Forwarder start error:") + tr(strerror(errno)));
750 return; 758 return;
751 } 759 }
760 connect(forwarder, SIGNAL(processExited(Opie::Core::OProcess*)),
761 this, SLOT(forwardExited(Opie::Core::OProcess*)));
752 runButton->setText("stop gateway"); 762 runButton->setText("stop gateway");
753#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 763#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
754 QCopEnvelope("QPE/System", "setScreenSaverMode(int)") 764 {
755 << QPEApplication::DisableSuspend; 765 odebug << "SUSP: Disable suspend mode" << oendl;
766 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)");
767 e << QPEApplication::DisableSuspend;
768 }
756#endif 769#endif
757} 770}
758 771
759/** 772/**
760 * React on the process end 773 * React on the process end
761 */ 774 */
762void BlueBase::forwardExit(Opie::Core::OProcess* proc) 775void BlueBase::forwardExit(Opie::Core::OProcess* proc)
763{ 776{
777 odebug << "Process exited" << oendl;
764#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 778#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
765 QCopEnvelope("QPE/System", "setScreenSaverMode(int)" ) 779 if (forwarder) {
766 << QPEApplication::Enable; 780 delete forwarder;
781 forwarder = NULL;
782 runButton->setText("start gateway");
783 odebug << "SUSP: Enable suspend mode" << oendl;
784 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
785 e << QPEApplication::Enable;
786 }
767#endif 787#endif
768 if (proc->exitStatus() != 0) 788 if (proc->exitStatus() != 0)
769 QMessageBox::critical(this, tr("Forwarder Error"), 789 QMessageBox::critical(this, tr("Forwarder Error"),
770 tr("Forwarder start error")); 790 tr("Forwarder start error"));
771 delete proc;
772 forwarder = NULL;
773 runButton->setText("start gateway");
774} 791}
775 792
776/** 793/**
777 * Encrypt entered passkey 794 * Encrypt entered passkey
778 * doit - do encryption of the key 795 * doit - do encryption of the key
779 */ 796 */
780void BlueBase::doEncrypt(bool doit) 797void BlueBase::doEncrypt(bool doit)
781{ 798{
782 passkeyLine->setEchoMode((doit)? QLineEdit::Password: QLineEdit::Normal); 799 passkeyLine->setEchoMode((doit)? QLineEdit::Password: QLineEdit::Normal);
783} 800}
784 801
785/** 802/**
786 * Start services edit dialog 803 * Start services edit dialog
787 */ 804 */
788void BlueBase::editServices() 805void BlueBase::editServices()
789{ 806{
790 QString conf = "/etc/default/bluetooth"; 807 QString conf = "/etc/default/bluetooth";
791//// Use for debugging purposes 808//// Use for debugging purposes
792//// QString conf = "/mnt/net/opie/bin/bluetooth"; 809//// QString conf = "/mnt/net/opie/bin/bluetooth";
793 ServicesDialog svcEdit(conf, this, "ServicesDialog", true, 810 ServicesDialog svcEdit(conf, this, "ServicesDialog", true,
794 WStyle_ContextHelp); 811 WStyle_ContextHelp);
795 812
796 if (QPEApplication::execDialog(&svcEdit) == QDialog::Accepted) 813 if (QPEApplication::execDialog(&svcEdit) == QDialog::Accepted)
797 { 814 {
798 } 815 }
799} 816}
800 817
801//eof 818//eof
diff --git a/noncore/net/opietooth/manager/obexftpdialog.cpp b/noncore/net/opietooth/manager/obexftpdialog.cpp
index fd2015e..2f04ecf 100644
--- a/noncore/net/opietooth/manager/obexftpdialog.cpp
+++ b/noncore/net/opietooth/manager/obexftpdialog.cpp
@@ -1,548 +1,548 @@
1/* $Id$ */ 1/* $Id$ */
2/* OBEX file browser dialog */ 2/* OBEX file browser dialog */
3/*************************************************************************** 3/***************************************************************************
4 * * 4 * *
5 * This program is free software; you can redistribute it and/or modify * 5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by * 6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or * 7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. * 8 * (at your option) any later version. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11/* 11/*
12 * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/ 12 * This code uses and is based on ObexFTP project code: http://triq.net/obexftp/
13 */ 13 */
14#include <sys/stat.h> 14#include <sys/stat.h>
15#include <sys/types.h> 15#include <sys/types.h>
16#include <unistd.h> 16#include <unistd.h>
17#include <string.h> 17#include <string.h>
18#include <errno.h> 18#include <errno.h>
19#include <qpushbutton.h> 19#include <qpushbutton.h>
20#include <qmessagebox.h> 20#include <qmessagebox.h>
21#include <qmultilineedit.h> 21#include <qmultilineedit.h>
22#include <qlineedit.h> 22#include <qlineedit.h>
23#include <qspinbox.h> 23#include <qspinbox.h>
24#include <qcombobox.h> 24#include <qcombobox.h>
25#include <qlistview.h> 25#include <qlistview.h>
26#include <qprogressbar.h> 26#include <qprogressbar.h>
27#include <qlabel.h> 27#include <qlabel.h>
28#include <qlayout.h> 28#include <qlayout.h>
29#include <errno.h> 29#include <errno.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qtextstream.h> 31#include <qtextstream.h>
32#include <qstringlist.h> 32#include <qstringlist.h>
33#include "obexftpdialog.h" 33#include "obexftpdialog.h"
34#include "filelistitem.h" 34#include "filelistitem.h"
35 35
36#include <qpe/qpeapplication.h> 36#include <qpe/qpeapplication.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <qpe/config.h> 38#include <qpe/config.h>
39#include <opie2/odebug.h> 39#include <opie2/odebug.h>
40#include <opie2/ofileselector.h> 40#include <opie2/ofileselector.h>
41#include <opie2/ofiledialog.h> 41#include <opie2/ofiledialog.h>
42 42
43using namespace Opie::Core; 43using namespace Opie::Core;
44using namespace Opie::Ui; 44using namespace Opie::Ui;
45 45
46using namespace OpieTooth; 46using namespace OpieTooth;
47 47
48#define MAX_PROGRESS 14 //Maximal progress bar 48#define MAX_PROGRESS 14 //Maximal progress bar
49 49
50static void info_cb(int event, const char *msg, int len, void* data); 50static void info_cb(int event, const char *msg, int len, void* data);
51 51
52/* 52/*
53 * Public constructor 53 * Public constructor
54 * device - bluetooth address of the device 54 * device - bluetooth address of the device
55 * port - port to connect to 55 * port - port to connect to
56 */ 56 */
57ObexFtpDialog::ObexFtpDialog(const QString& device, int port, 57ObexFtpDialog::ObexFtpDialog(const QString& device, int port,
58 QWidget* parent, const char* name, bool modal, WFlags fl) 58 QWidget* parent, const char* name, bool modal, WFlags fl)
59 : ObexFtpDialogBase(parent, name, modal, fl), m_device(device), 59 : ObexFtpDialogBase(parent, name, modal, fl), m_device(device),
60 m_port(port), curdir("") 60 m_port(port), curdir("")
61{ 61{
62 client = NULL; 62 client = NULL;
63 nRetries = 3; 63 nRetries = 3;
64 transport = OBEX_TRANS_BLUETOOTH; 64 transport = OBEX_TRANS_BLUETOOTH;
65 use_conn = TRUE; 65 use_conn = TRUE;
66 use_path = TRUE; 66 use_path = TRUE;
67 progressStatus = 0; 67 progressStatus = 0;
68 localCurdir = "/"; 68 localCurdir = "/";
69 browseLog->setEdited(FALSE); 69 browseLog->setEdited(FALSE);
70 fileList->setSorting(1); 70 fileList->setSorting(1);
71 fileList->clear(); 71 fileList->clear();
72 fileProgress->setTotalSteps(MAX_PROGRESS); 72 fileProgress->setTotalSteps(MAX_PROGRESS);
73 statusBar->clear(); 73 statusBar->clear();
74 localLayout = new QVBoxLayout(localFs); 74 localLayout = new QVBoxLayout(localFs);
75 localLayout->setSpacing( 0 ); 75 localLayout->setSpacing( 0 );
76 localLayout->setMargin( 0 ); 76 localLayout->setMargin( 0 );
77 destFile = new OFileSelector(localFs, 77 destFile = new OFileSelector(localFs,
78 OFileSelector::FileSelector, 78 OFileSelector::FileSelector,
79 OFileSelector::ExtendedAll, localCurdir, ""); 79 OFileSelector::ExtendedAll, localCurdir, "");
80 destFile->setCloseVisible(false); 80 destFile->setCloseVisible(false);
81 destFile->setNewVisible(false); 81 destFile->setNewVisible(false);
82 localLayout->addWidget(destFile); 82 localLayout->addWidget(destFile);
83 nReries->setValue(nRetries); 83 nReries->setValue(nRetries);
84 connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse())); 84 connect(browseOK, SIGNAL(clicked()), SLOT(slotBrowse()));
85 connect(fileList, SIGNAL(clicked(QListViewItem*)), 85 connect(fileList, SIGNAL(clicked(QListViewItem*)),
86 SLOT(slotCd(QListViewItem*))); 86 SLOT(slotCd(QListViewItem*)));
87 connect(getButton, 87 connect(getButton,
88 SIGNAL(clicked()), 88 SIGNAL(clicked()),
89 SLOT(getFile())); 89 SLOT(getFile()));
90 connect(putButton, 90 connect(putButton,
91 SIGNAL(clicked()), 91 SIGNAL(clicked()),
92 SLOT(putFile())); 92 SLOT(putFile()));
93 connect(delButton, 93 connect(delButton,
94 SIGNAL(clicked()), 94 SIGNAL(clicked()),
95 SLOT(delFile())); 95 SLOT(delFile()));
96 connect(destFile, 96 connect(destFile,
97 SIGNAL(dirSelected (const QString&)), 97 SIGNAL(dirSelected (const QString&)),
98 SLOT(updateDir(const QString&))); 98 SLOT(updateDir(const QString&)));
99 connect(saveButton, 99 connect(saveButton,
100 SIGNAL(clicked()), 100 SIGNAL(clicked()),
101 SLOT(slotSaveLog())); 101 SLOT(slotSaveLog()));
102 connect(browseButton, 102 connect(browseButton,
103 SIGNAL(clicked()), 103 SIGNAL(clicked()),
104 SLOT(slotBrowseLog())); 104 SLOT(slotBrowseLog()));
105} 105}
106 106
107ObexFtpDialog::~ObexFtpDialog() 107ObexFtpDialog::~ObexFtpDialog()
108{ 108{
109 if (client != NULL) { 109 if (client != NULL) {
110 obexftp_disconnect(client); 110 obexftp_disconnect(client);
111 obexftp_close(client); 111 obexftp_close(client);
112 } 112 }
113} 113}
114 114
115/* 115/*
116 * Do device browsing 116 * Do device browsing
117 */ 117 */
118void ObexFtpDialog::slotBrowse() 118void ObexFtpDialog::slotBrowse()
119{ 119{
120 stat_entry_t* ent; //Directory entry 120 stat_entry_t* ent; //Directory entry
121 void *dir; //Directory to read 121 void *dir; //Directory to read
122 const uint8_t* use_uuid; //uuid 122 const uint8_t* use_uuid; //uuid
123 int len; //uuid length 123 int len; //uuid length
124 FileListItem* root; //root node 124 FileListItem* root; //root node
125 int fsize; //file size 125 int fsize; //file size
126 bool numOk; //true if the string is a number 126 bool numOk; //true if the string is a number
127 int tmp; //just a temp var 127 int tmp; //just a temp var
128 128
129 status(tr("Connecting to ") + m_device); 129 status(tr("Connecting to ") + m_device);
130 odebug << "Browse device " << m_device << oendl; 130 odebug << "Browse device " << m_device << oendl;
131 browseLog->clear(); 131 browseLog->clear();
132 fileList->clear(); 132 fileList->clear();
133 progressStatus = 0; 133 progressStatus = 0;
134 fileProgress->setTotalSteps(MAX_PROGRESS); 134 fileProgress->setTotalSteps(MAX_PROGRESS);
135 fileProgress->reset(); 135 fileProgress->reset();
136 136
137 //Get parameters 137 //Get parameters
138 tmp = nReries->text().toInt(&numOk); 138 tmp = nReries->text().toInt(&numOk);
139 if (numOk) 139 if (numOk)
140 nRetries = tmp; 140 nRetries = tmp;
141 if (uuidType->currentText() == "FBS") { 141 if (uuidType->currentText() == "FBS") {
142 use_uuid = UUID_FBS; 142 use_uuid = UUID_FBS;
143 len = sizeof(UUID_FBS); 143 len = sizeof(UUID_FBS);
144 } else if (uuidType->currentText() == "S45") { 144 } else if (uuidType->currentText() == "S45") {
145 use_uuid = UUID_S45; 145 use_uuid = UUID_S45;
146 len = sizeof(UUID_S45); 146 len = sizeof(UUID_S45);
147 } else { 147 } else {
148 use_uuid = UUID_FBS; 148 use_uuid = UUID_FBS;
149 len = sizeof(UUID_FBS); 149 len = sizeof(UUID_FBS);
150 } 150 }
151 151
152 if (!cli_connect_uuid(use_uuid, len)) { 152 if (!cli_connect_uuid(use_uuid, len)) {
153 log(tr("Connection failed: ") + tr(strerror(errno))); 153 log(tr("Connection failed: ") + tr(strerror(errno)));
154 errBox("Connection failed"); 154 errBox("Connection failed");
155 status("Connection failed"); 155 status("Connection failed");
156 return; 156 return;
157 } 157 }
158 else { 158 else {
159 log(QString("Connected to ") + m_device); 159 log(QString("Connected to ") + m_device);
160 status(QString("Connected to ") + m_device); 160 status(QString("Connected to ") + m_device);
161 } 161 }
162 /* List folder */ 162 /* List folder */
163 root = new FileListItem(fileList, NULL); 163 root = new FileListItem(fileList, NULL);
164 dir = obexftp_opendir(client, curdir); 164 dir = obexftp_opendir(client, curdir);
165 while ((ent = obexftp_readdir(dir)) != NULL) { 165 while ((ent = obexftp_readdir(dir)) != NULL) {
166 FileListItem* a; //List view item 166 FileListItem* a; //List view item
167 if (ent->mode != 16877) { 167 if (ent->mode != 16877) {
168 fsize = ent->size; 168 fsize = ent->size;
169 } 169 }
170 else 170 else
171 fsize = 0; 171 fsize = 0;
172 log(QString(ent->name) + QString(" ") + 172 log(QString(ent->name) + QString(" ") +
173 QString::number(ent->mode)); 173 QString::number(ent->mode));
174 174
175 a = new FileListItem(fileList, ent, fsize); 175 a = new FileListItem(fileList, ent, fsize);
176 } 176 }
177 obexftp_closedir(dir); 177 obexftp_closedir(dir);
178} 178}
179 179
180//Error message box 180//Error message box
181int ObexFtpDialog::errBox(QCString msg) 181int ObexFtpDialog::errBox(QCString msg)
182{ 182{
183 return QMessageBox::critical(this, tr("ObexFTP error"), msg); 183 return QMessageBox::critical(this, tr("ObexFTP error"), msg);
184} 184}
185 185
186int ObexFtpDialog::errBox(QString msg) 186int ObexFtpDialog::errBox(QString msg)
187{ 187{
188 return QMessageBox::critical(this, tr("ObexFTP error"), msg); 188 return QMessageBox::critical(this, tr("ObexFTP error"), msg);
189} 189}
190 190
191int ObexFtpDialog::errBox(const char* msg) 191int ObexFtpDialog::errBox(const char* msg)
192{ 192{
193 return QMessageBox::critical(this, tr("ObexFTP error"), tr(msg)); 193 return QMessageBox::critical(this, tr("ObexFTP error"), tr(msg));
194} 194}
195 195
196//Text in the status bar 196//Text in the status bar
197void ObexFtpDialog::status(QCString msg) 197void ObexFtpDialog::status(QCString msg)
198{ 198{
199 statusBar->setText(msg); 199 statusBar->setText(msg);
200 statusBar->repaint(); 200 statusBar->repaint();
201} 201}
202 202
203void ObexFtpDialog::status(QString msg) 203void ObexFtpDialog::status(QString msg)
204{ 204{
205 statusBar->setText(msg); 205 statusBar->setText(msg);
206 statusBar->repaint(); 206 statusBar->repaint();
207} 207}
208 208
209void ObexFtpDialog::status(const char* msg) 209void ObexFtpDialog::status(const char* msg)
210{ 210{
211 statusBar->setText(msg); 211 statusBar->setText(msg);
212 statusBar->repaint(); 212 statusBar->repaint();
213} 213}
214 214
215/* 215/*
216 * Change directory with item under the cursor 216 * Change directory with item under the cursor
217 */ 217 */
218void ObexFtpDialog::slotCd(QListViewItem* item) 218void ObexFtpDialog::slotCd(QListViewItem* item)
219{ 219{
220 FileListItem* file = (FileListItem*)item; 220 FileListItem* file = (FileListItem*)item;
221 int idx; 221 int idx;
222 if (file == NULL) 222 if (file == NULL)
223 return; 223 return;
224 odebug << "Item " << file->text(0) << " clicked" << oendl; 224 odebug << "Item " << file->text(0) << " clicked" << oendl;
225 if (file->gettype() == IS_DIR) { 225 if (file->gettype() == IS_DIR) {
226 if (file->text(0) == "../") { 226 if (file->text(0) == "../") {
227 if (curdir.right(1) == "/") 227 if (curdir.right(1) == "/")
228 curdir.remove(curdir.length() - 1, 1); 228 curdir.remove(curdir.length() - 1, 1);
229 idx = curdir.findRev('/'); 229 idx = curdir.findRev('/');
230 if (idx >= 0) 230 if (idx >= 0)
231 curdir.remove(idx, curdir.length() - idx); 231 curdir.remove(idx, curdir.length() - idx);
232 else 232 else
233 curdir = ""; 233 curdir = "";
234 } 234 }
235 else { 235 else {
236 if (curdir != "" && curdir.right(1) != "/") 236 if (curdir != "" && curdir.right(1) != "/")
237 curdir += "/"; 237 curdir += "/";
238 curdir += file->text(0); 238 curdir += file->text(0);
239 } 239 }
240 odebug << "Browse " << curdir << oendl; 240 odebug << "Browse " << curdir << oendl;
241 if (obexftp_setpath(client, curdir, 0) < 0) 241 if (obexftp_setpath(client, curdir, 0) < 0)
242 log(tr("CD failed: ") + tr(strerror(errno))); 242 log(tr("CD failed: ") + tr(strerror(errno)));
243 slotBrowse(); 243 slotBrowse();
244 } 244 }
245} 245}
246 246
247/* 247/*
248 * Copy file from a remote device to the local device 248 * Copy file from a remote device to the local device
249 */ 249 */
250void ObexFtpDialog::getFile() 250void ObexFtpDialog::getFile()
251{ 251{
252 FileListItem* file = (FileListItem*)fileList->selectedItem(); 252 FileListItem* file = (FileListItem*)fileList->selectedItem();
253 int result; 253 int result;
254 if (file == NULL) 254 if (file == NULL)
255 return; 255 return;
256 file2get = "/"; 256 file2get = "/";
257 local = localCurdir; 257 local = localCurdir;
258 if (local == "") { 258 if (local == "") {
259 errBox("Select a destination first"); 259 errBox("Select a destination first");
260 return; 260 return;
261 } 261 }
262 if (local.right(1) != "/") 262 if (local.right(1) != "/")
263 local += "/"; 263 local += "/";
264 if (file->gettype() == IS_FILE) { 264 if (file->gettype() == IS_FILE) {
265 if (client == NULL) { 265 if (client == NULL) {
266 errBox("No connection established"); 266 errBox("No connection established");
267 return; 267 return;
268 } 268 }
269 file2get += curdir; 269 file2get += curdir;
270 if (curdir != "" && curdir.right(1) != "/") 270 if (curdir != "" && curdir.right(1) != "/")
271 file2get += "/"; 271 file2get += "/";
272 file2get += file->text(0); 272 file2get += file->text(0);
273 local += file->text(0); 273 local += file->text(0);
274 odebug << "Copy " << file2get << " to " << local << oendl; 274 odebug << "Copy " << file2get << " to " << local << oendl;
275 progressStatus = 0; 275 progressStatus = 0;
276 fileProgress->setTotalSteps(file->getsize() / 1024); 276 fileProgress->setTotalSteps(file->getsize() / 1024);
277 fileProgress->reset(); 277 fileProgress->reset();
278 status(tr("Receiving file ") + file2get); 278 status(tr("Receiving file ") + file2get);
279 result = obexftp_get(client, local, file2get); 279 result = obexftp_get(client, local, file2get);
280 if (result < 0) { 280 if (result < 0) {
281 log(file2get + QString(" receive ERROR:\n") + tr(strerror(errno))); 281 log(file2get + QString(" receive ERROR:\n") + tr(strerror(errno)));
282 errBox(file2get + QString(" receive ERROR")); 282 errBox(file2get + QString(" receive ERROR"));
283 status(file2get + QString(" receive ERROR")); 283 status(file2get + QString(" receive ERROR"));
284 } 284 }
285 else { 285 else {
286 log(file2get + QString(" received")); 286 log(file2get + QString(" received"));
287 status(file2get + QString(" received")); 287 status(file2get + QString(" received"));
288 destFile->reread(); 288 destFile->reread();
289 } 289 }
290 } 290 }
291} 291}
292 292
293/* 293/*
294 * Copy file from the local device to a remote device 294 * Copy file from the local device to a remote device
295 */ 295 */
296void ObexFtpDialog::putFile() 296void ObexFtpDialog::putFile()
297{ 297{
298 int result; //OPeration result 298 int result; //OPeration result
299 int idx; //Index of a symbol in the string 299 int idx; //Index of a symbol in the string
300 struct stat localFStat; //Local file information 300 struct stat localFStat; //Local file information
301 301
302 if (client == NULL) { 302 if (client == NULL) {
303 errBox("No connection established"); 303 errBox("No connection established");
304 return; 304 return;
305 } 305 }
306 local = destFile->selectedName(); 306 local = destFile->selectedName();
307 if (local == "") { 307 if (local == "") {
308 errBox("No file slected"); 308 errBox("No file slected");
309 return; 309 return;
310 } 310 }
311 result = stat(local, &localFStat); 311 result = stat(local, &localFStat);
312 if (result < 0) { 312 if (result < 0) {
313 errBox(tr("Wrong file selected ") + local + tr(" ") + 313 errBox(tr("Wrong file selected ") + local + tr(" ") +
314 tr(strerror(errno))); 314 tr(strerror(errno)));
315 return; 315 return;
316 } 316 }
317 idx = local.findRev('/'); 317 idx = local.findRev('/');
318 if (idx > 0) { 318 if (idx > 0) {
319 file2get = local.right(local.length() - idx - 1); 319 file2get = local.right(local.length() - idx - 1);
320 } 320 }
321 else 321 else
322 file2get = local; 322 file2get = local;
323 323
324 odebug << "Copy " << local << " to " << file2get << oendl; 324 odebug << "Copy " << local << " to " << file2get << oendl;
325 progressStatus = 0; 325 progressStatus = 0;
326 fileProgress->setTotalSteps(localFStat.st_size / 1024); 326 fileProgress->setTotalSteps(localFStat.st_size / 1024);
327 fileProgress->reset(); 327 fileProgress->reset();
328 status(tr("Sending file ") + local); 328 status(tr("Sending file ") + local);
329 result = obexftp_put_file(client, local, file2get); 329 result = obexftp_put_file(client, local, file2get);
330 if (result < 0) { 330 if (result < 0) {
331 log(local + QString(" send ERROR:\n") + tr(strerror(errno))); 331 log(local + QString(" send ERROR:\n") + tr(strerror(errno)));
332 errBox(local + QString(" send ERROR")); 332 errBox(local + QString(" send ERROR"));
333 status(local + QString(" send ERROR")); 333 status(local + QString(" send ERROR"));
334 } 334 }
335 else { 335 else {
336 slotBrowse(); 336 slotBrowse();
337 log(local + QString(" sent")); 337 log(local + QString(" sent"));
338 status(local + QString(" sent")); 338 status(local + QString(" sent"));
339 } 339 }
340} 340}
341 341
342/* 342/*
343 * Delete file on a remote device 343 * Delete file on a remote device
344 */ 344 */
345void ObexFtpDialog::delFile() 345void ObexFtpDialog::delFile()
346{ 346{
347 FileListItem* file = (FileListItem*)fileList->selectedItem(); 347 FileListItem* file = (FileListItem*)fileList->selectedItem();
348 int result; 348 int result;
349 if (file == NULL) 349 if (file == NULL)
350 return; 350 return;
351 file2get = "/"; 351 file2get = "/";
352 if (file->gettype() == IS_FILE) { 352 if (file->gettype() == IS_FILE) {
353 if (client == NULL) { 353 if (client == NULL) {
354 errBox("No connection established"); 354 errBox("No connection established");
355 return; 355 return;
356 } 356 }
357 file2get += curdir; 357 file2get += curdir;
358 if (curdir != "" && curdir.right(1) != "/") 358 if (curdir != "" && curdir.right(1) != "/")
359 file2get += "/"; 359 file2get += "/";
360 file2get += file->text(0); 360 file2get += file->text(0);
361 } 361 }
362 result = QMessageBox::warning(this, tr("Remove File"), 362 result = QMessageBox::warning(this, tr("Remove File"),
363 tr("Do you want to remove\n") + file2get, "Yes", "No"); 363 tr("Do you want to remove\n") + file2get, "Yes", "No");
364 if (result != 0) 364 if (result != 0)
365 return; 365 return;
366 odebug << "Remove " << file2get << oendl; 366 odebug << "Remove " << file2get << oendl;
367 result = obexftp_del(client, file2get); 367 result = obexftp_del(client, file2get);
368 if (result < 0) { 368 if (result < 0) {
369 log(file2get + QString(" remove ERROR\n") + tr(strerror(errno))); 369 log(file2get + QString(" remove ERROR\n") + tr(strerror(errno)));
370 errBox(file2get + QString(" remove ERROR")); 370 errBox(file2get + QString(" remove ERROR"));
371 status(file2get + QString(" remove ERROR")); 371 status(file2get + QString(" remove ERROR"));
372 } 372 }
373 else { 373 else {
374 slotBrowse(); 374 slotBrowse();
375 log(file2get + QString(" removed")); 375 log(file2get + QString(" removed"));
376 status(file2get + QString(" removed")); 376 status(file2get + QString(" removed"));
377 } 377 }
378} 378}
379 379
380/* connect with given uuid. re-connect every time */ 380/* connect with given uuid. re-connect every time */
381int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len) 381int ObexFtpDialog::cli_connect_uuid(const uint8_t *uuid, int uuid_len)
382{ 382{
383 int retry; 383 int retry;
384 if (client != NULL) 384 if (client != NULL)
385 return TRUE; 385 return TRUE;
386 /* Open */ 386 /* Open */
387 client = obexftp_open (transport, NULL, info_cb, this); 387 client = obexftp_open (transport, NULL, info_cb, this);
388 if(client == NULL) { 388 if(client == NULL) {
389 errBox("Error opening obexftp-client"); 389 errBox("Error opening obexftp-client");
390 return FALSE; 390 return FALSE;
391 } 391 }
392 if (!use_conn) 392 if (!use_conn)
393 client->quirks &= ~OBEXFTP_CONN_HEADER; 393 client->quirks &= ~OBEXFTP_CONN_HEADER;
394 if (!use_path) 394 if (!use_path)
395 client->quirks &= ~OBEXFTP_SPLIT_SETPATH; 395 client->quirks &= ~OBEXFTP_SPLIT_SETPATH;
396 for (retry = 0; retry < nRetries; retry++) { 396 for (retry = 0; retry < nRetries; retry++) {
397 /* Connect */ 397 /* Connect */
398 switch (transport) { 398 switch (transport) {
399 case OBEX_TRANS_IRDA: 399 case OBEX_TRANS_IRDA:
400 if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0) 400 if (obexftp_connect_uuid(client, NULL, 0, uuid, uuid_len) >= 0)
401 return TRUE; 401 return TRUE;
402 break; 402 break;
403 case OBEX_TRANS_BLUETOOTH: 403 case OBEX_TRANS_BLUETOOTH:
404 if (obexftp_connect_uuid(client, m_device, m_port, 404 if (obexftp_connect_uuid(client, m_device, m_port,
405 uuid, uuid_len) >= 0) 405 uuid, uuid_len) >= 0)
406 return TRUE; 406 return TRUE;
407 break; 407 break;
408 default: 408 default:
409 errBox("Transport type unknown"); 409 errBox("Transport type unknown");
410 return FALSE; 410 return FALSE;
411 } 411 }
412 log(tr("Still trying to connect")); 412 log(tr("Still trying to connect"));
413 } 413 }
414 client = NULL; 414 client = NULL;
415 415
416 return FALSE; 416 return FALSE;
417} 417}
418 418
419/* 419/*
420 * Put a message to the log window 420 * Put a message to the log window
421 */ 421 */
422void ObexFtpDialog::log(QString str) 422void ObexFtpDialog::log(QString str)
423{ 423{
424 browseLog->append(str); 424 browseLog->append(str);
425} 425}
426 426
427void ObexFtpDialog::log(QCString str) 427void ObexFtpDialog::log(QCString str)
428{ 428{
429 browseLog->append(str); 429 browseLog->append(str);
430} 430}
431 431
432void ObexFtpDialog::log(QString& str) 432void ObexFtpDialog::log(QString& str)
433{ 433{
434 browseLog->append(str); 434 browseLog->append(str);
435} 435}
436 436
437void ObexFtpDialog::log(const char* str) 437void ObexFtpDialog::log(const char* str)
438{ 438{
439 browseLog->append(str); 439 browseLog->append(str);
440} 440}
441 441
442void ObexFtpDialog::incProgress() 442void ObexFtpDialog::incProgress()
443{ 443{
444 if (progressStatus < fileProgress->totalSteps()) 444 if (progressStatus < fileProgress->totalSteps())
445 fileProgress->setProgress(progressStatus++); 445 fileProgress->setProgress(progressStatus++);
446} 446}
447 447
448void ObexFtpDialog::doneProgress() 448void ObexFtpDialog::doneProgress()
449{ 449{
450 progressStatus = 0; 450 progressStatus = 0;
451 fileProgress->reset(); 451 fileProgress->reset();
452} 452}
453 453
454void ObexFtpDialog::updateDir(const QString& newdir) 454void ObexFtpDialog::updateDir(const QString& newdir)
455{ 455{
456 localCurdir = newdir; 456 localCurdir = newdir;
457} 457}
458 458
459/** 459/**
460 * Save Log to the specified file 460 * Save Log to the specified file
461 */ 461 */
462void ObexFtpDialog::slotSaveLog() 462void ObexFtpDialog::slotSaveLog()
463{ 463{
464 QFile logFile(saveLogEdit->text()); 464 QFile logFile(saveLogEdit->text());
465 if (!logFile.open(IO_WriteOnly)) { 465 if (!logFile.open(IO_WriteOnly)) {
466 errBox(tr("Unable to open file ") + saveLogEdit->text() + tr(" ") + 466 errBox(tr("Unable to open file ") + saveLogEdit->text() + tr(" ") +
467 tr(strerror(errno))); 467 tr(strerror(errno)));
468 return; 468 return;
469 } 469 }
470 QTextStream stream(&logFile); 470 QTextStream stream(&logFile);
471 stream << browseLog->text() << endl; 471 stream << browseLog->text() << endl;
472 QMessageBox::information(this, tr("Saving"), 472 QMessageBox::information(this, tr("Saving"),
473 tr("Log file saved to ") + saveLogEdit->text()); 473 tr("Log file saved to ") + saveLogEdit->text());
474} 474}
475 475
476void ObexFtpDialog::slotBrowseLog() 476void ObexFtpDialog::slotBrowseLog()
477{ 477{
478 MimeTypes types; 478 MimeTypes types;
479 QStringList all; 479 QStringList all;
480 all << "*/*"; 480 all << "*/*";
481 types.insert("All Files", all ); 481 types.insert("All Files", all );
482 482
483 QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 ); 483 QString str = OFileDialog::getOpenFileName( 1,"/","", types, 0 );
484 saveLogEdit->setText(str); 484 saveLogEdit->setText(str);
485} 485}
486 486
487/* 487/*
488 * Event callback function 488 * Event callback function
489 */ 489 */
490static void info_cb(int event, const char *msg, int len, void* data) 490static void info_cb(int event, const char *msg, int len, void* data)
491{ 491{
492 ObexFtpDialog* dlg = (ObexFtpDialog*)data; 492 ObexFtpDialog* dlg = (ObexFtpDialog*)data;
493 QCString cmsg(msg, len); //Message to display 493 QCString cmsg(msg, len); //Message to display
494 494
495 switch (event) { 495 switch (event) {
496 496
497 case OBEXFTP_EV_ERRMSG: 497 case OBEXFTP_EV_ERRMSG:
498 dlg->log(QCString("Error: ") + cmsg); 498 dlg->log(QCString("Error: ") + cmsg);
499 break; 499 break;
500 500
501 case OBEXFTP_EV_ERR: 501 case OBEXFTP_EV_ERR:
502 dlg->log(QCString("failed: ") + cmsg); 502 dlg->log(QCString("failed: ") + cmsg);
503 dlg->doneProgress(); 503 dlg->doneProgress();
504 break; 504 break;
505 case OBEXFTP_EV_OK: 505 case OBEXFTP_EV_OK:
506 dlg->log(QCString("done")); 506 dlg->log(QCString("done"));
507 dlg->doneProgress(); 507 dlg->doneProgress();
508 break; 508 break;
509 509
510 case OBEXFTP_EV_CONNECTING: 510 case OBEXFTP_EV_CONNECTING:
511 dlg->log(QCString("Connecting...")); 511 dlg->log(QCString("Connecting..."));
512 break; 512 break;
513 case OBEXFTP_EV_DISCONNECTING: 513 case OBEXFTP_EV_DISCONNECTING:
514 dlg->log(QCString("Disconnecting...")); 514 dlg->log(QCString("Disconnecting..."));
515 break; 515 break;
516 case OBEXFTP_EV_SENDING: 516 case OBEXFTP_EV_SENDING:
517 dlg->log(QCString("Sending ") + msg); 517 dlg->log(QCString("Sending ") + msg);
518 break; 518 break;
519 case OBEXFTP_EV_RECEIVING: 519 case OBEXFTP_EV_RECEIVING:
520 dlg->log(QCString("Receiving ") + msg); 520 dlg->log(QCString("Receiving ") + msg);
521 break; 521 break;
522 522
523 case OBEXFTP_EV_LISTENING: 523 case OBEXFTP_EV_LISTENING:
524 dlg->log(QCString("Waiting for incoming connection")); 524 dlg->log(QCString("Waiting for incoming connection"));
525 break; 525 break;
526 526
527 case OBEXFTP_EV_CONNECTIND: 527 case OBEXFTP_EV_CONNECTIND:
528 dlg->log(QCString("Incoming connection")); 528 dlg->log(QCString("Incoming connection"));
529 break; 529 break;
530 case OBEXFTP_EV_DISCONNECTIND: 530 case OBEXFTP_EV_DISCONNECTIND:
531 dlg->log(QCString("Disconnecting")); 531 dlg->log(QCString("Disconnecting"));
532 break; 532 break;
533 533
534 case OBEXFTP_EV_INFO: 534 case OBEXFTP_EV_INFO:
535 // 64 bit problems ? 535 // 64 bit problems ?
536 dlg->log(QString("Got info ") + QString::number((int)msg)); 536 dlg->log(QString("Got info ") + QString::number((int)msg));
537 break; 537 break;
538 538
539 case OBEXFTP_EV_BODY: 539 case OBEXFTP_EV_BODY:
540 break; 540 break;
541 541
542 case OBEXFTP_EV_PROGRESS: 542 case OBEXFTP_EV_PROGRESS:
543 dlg->incProgress(); 543 dlg->incProgress();
544 break; 544 break;
545 } 545 }
546} 546}
547 547
548//eof 548//eof