summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2006-05-02 08:57:25 (UTC)
committer mickeyl <mickeyl>2006-05-02 08:57:25 (UTC)
commitd5b6868cb4f99d2c3dc3587115cd37c09e4610eb (patch) (unidiff)
tree1397f12f885c849419e511ad203d19696c4ae07e
parent1295db77f2ab7e9125183e4240de0b92f72940e4 (diff)
downloadopie-d5b6868cb4f99d2c3dc3587115cd37c09e4610eb.zip
opie-d5b6868cb4f99d2c3dc3587115cd37c09e4610eb.tar.gz
opie-d5b6868cb4f99d2c3dc3587115cd37c09e4610eb.tar.bz2
bluetooth patches courtesy Dmitriy Korovkin (thanks!):
* When sending data to a device, do service discovery in order to get port number. * Switched to ussp-push for sending. * Clear receivers list on rescan. * Changed the way of window closing in order to shut down IRDA and bluetooth correctly.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/btobex.cpp85
-rw-r--r--core/obex/btobex.h8
-rw-r--r--core/obex/obex.pro4
-rw-r--r--core/obex/obexsend.cpp26
4 files changed, 94 insertions, 29 deletions
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index a2866f6..bb5c06d 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -1,197 +1,254 @@
1 1
2#include "btobex.h" 2#include "btobex.h"
3#include <manager.h>
4#include <services.h>
3 5
4/* OPIE */ 6/* OPIE */
5#include <opie2/oprocess.h> 7#include <opie2/oprocess.h>
6#include <opie2/odebug.h> 8#include <opie2/odebug.h>
7 9
8/* QT */ 10/* QT */
9#include <qfileinfo.h> 11#include <qfileinfo.h>
10 12#include <qstring.h>
11 13#include <qmap.h>
14#include <qmessagebox.h>
12 15
13using namespace OpieObex; 16using namespace OpieObex;
14 17
15using namespace Opie::Core; 18using namespace Opie::Core;
16/* TRANSLATOR OpieObex::Obex */ 19/* TRANSLATOR OpieObex::Obex */
20using namespace OpieTooth;
17 21
18BtObex::BtObex( QObject *parent, const char* name ) 22BtObex::BtObex( QObject *parent, const char* name )
19 : QObject(parent, name ) 23 : QObject(parent, name )
20{ 24{
21 m_rec = 0; 25 m_rec = 0;
22 m_send=0; 26 m_send=0;
23 m_count = 0; 27 m_count = 0;
24 m_receive = false; 28 m_receive = false;
25 connect( this, SIGNAL(error(int) ), // for recovering to receive 29 connect( this, SIGNAL(error(int) ), // for recovering to receive
26 SLOT(slotError() ) ); 30 SLOT(slotError() ) );
27 connect( this, SIGNAL(sent(bool) ), 31 connect( this, SIGNAL(sent(bool) ),
28 SLOT(slotError() ) ); 32 SLOT(slotError() ) );
33 btManager = NULL;
29}; 34};
35
30BtObex::~BtObex() { 36BtObex::~BtObex() {
37 if (btManager)
38 delete btManager;
31 delete m_rec; 39 delete m_rec;
32 delete m_send; 40 delete m_send;
33} 41}
42
34void BtObex::receive() { 43void BtObex::receive() {
35 m_receive = true; 44 m_receive = true;
36 m_outp = QString::null; 45 m_outp = QString::null;
37 m_rec = new OProcess(); 46 m_rec = new OProcess();
38 47
39 // TODO mbhaynie: No idea if this actually works -- maybe opd is better. 48 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
40 *m_rec << "obexftpd" << "-b"; 49 *m_rec << "obexftpd" << "-b";
41 // connect to the necessary slots 50 // connect to the necessary slots
42 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 51 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
43 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 52 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
44 53
45 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 54 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
46 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 55 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
47 56
48 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 57 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
49 emit done( false ); 58 emit done( false );
50 delete m_rec; 59 delete m_rec;
51 m_rec = 0; 60 m_rec = 0;
52 } 61 }
53} 62}
54 63
55void BtObex::send( const QString& fileName, const QString& bdaddr) { 64void BtObex::send( const QString& fileName, const QString& bdaddr) {
56 // if currently receiving stop it send receive 65 // if currently receiving stop it send receive
57 m_count = 0; 66 m_count = 0;
58 m_file = fileName; 67 m_file = fileName;
59 m_bdaddr = bdaddr; 68 m_bdaddr = bdaddr;
60 if (m_rec != 0 ) { 69 if (m_rec != 0 ) {
61 if (m_rec->isRunning() ) { 70 if (m_rec->isRunning() ) {
62 emit error(-1 ); 71 emit error(-1 );
63 delete m_rec; 72 delete m_rec;
64 m_rec = 0; 73 m_rec = 0;
65 74
66 }else{ 75 }else{
67 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 76 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
68 return; 77 return;
69 } 78 }
70 } 79 }
80 //Now we need to find out if the OBEX push is supported for this device
81 //And get the port number
82 if (!btManager) {
83 btManager = new Manager("hci0");
84 connect(btManager,
85 SIGNAL(foundServices(const QString&, Services::ValueList)),
86 this, SLOT(slotFoundServices(const QString&, Services::ValueList)));
87 }
88 btManager->searchServices(bdaddr);
89}
90
91/**
92 * This function reacts on the service discovery finish
93 */
94void BtObex::slotFoundServices(const QString&, Services::ValueList svcList)
95{
96 QValueList<OpieTooth::Services>::Iterator it;
97 QMap<int, QString> classList; //The classes list
98 QMap<int, QString>::Iterator classIt; //Iterator in the class list
99 int portNum = -1; //The desired port number
100 odebug << "BtObex slotFoundServices" << oendl;
101 if (svcList.isEmpty()) {
102 QMessageBox::critical(NULL, tr("Object send"), tr("No services found"));
103 emit error(-1);
104 return;
105 }
106 for (it = svcList.begin(); it != svcList.end(); it++) {
107 classList = (*it).classIdList();
108 classIt = classList.begin();
109 if (classIt == classList.end())
110 continue;
111////We really need symbolic names for service IDs
112 //Ok, we have found the object push service
113 if (classIt.key() == 4357) {
114 portNum = (*it).protocolDescriptorList().last().port();
115 break;
116 }
117 }
118 if (portNum == -1) {
119 QMessageBox::critical(NULL, tr("Object send"),
120 tr("No OBEX Push service"));
121 emit error(-1);
122 return;
123 }
124 m_port = portNum;
71 sendNow(); 125 sendNow();
72} 126}
127
73void BtObex::sendNow(){ 128void BtObex::sendNow(){
74 if ( m_count >= 25 ) { // could not send 129 if ( m_count >= 25 ) { // could not send
75 emit error(-1 ); 130 emit error(-1 );
76 emit sent(false); 131 emit sent(false);
77 return; 132 return;
78 } 133 }
79 // OProcess inititialisation 134 // OProcess inititialisation
80 m_send = new OProcess(); 135 m_send = new OProcess(0, "ussp-push");
81 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); 136 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) );
82 137
83 // obextool push file <bdaddr> [channel] 138 // ussp-push --timeo 30 <btaddr:port> file file
84 // 9 for phones. 139 *m_send << "ussp-push" << "--timeo 30";
85 // Palm T3 accepts pictures on 1 140 *m_send << m_bdaddr + "@" + QString::number(m_port);
86 *m_send << "obextool" << "push";
87 *m_send << QFile::encodeName(QFileInfo(m_file).fileName()); 141 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
88 *m_send << m_bdaddr << "9"; 142 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
89 143 m_send->setUseShell(true);
144
90 // connect to slots Exited and and StdOut 145 // connect to slots Exited and and StdOut
91 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), 146 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ),
92 this, SLOT(slotExited(Opie::Core::OProcess*)) ); 147 this, SLOT(slotExited(Opie::Core::OProcess*)) );
93 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), 148 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int)),
94 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 149 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
95
96 // now start it 150 // now start it
97 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 151 if (!m_send->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
98 m_count = 25; 152 m_count = 25;
99 emit error(-1 ); 153 emit error(-1 );
100 delete m_send; 154 delete m_send;
101 m_send=0; 155 m_send=0;
102 } 156 }
103 // end 157 // end
104 m_count++; 158 m_count++;
105 emit currentTry( m_count ); 159 emit currentTry( m_count );
106} 160}
107 161
108void BtObex::slotExited(OProcess* proc ){ 162void BtObex::slotExited(OProcess* proc ){
163 odebug << proc->name() << " exited with result "
164 << proc->exitStatus() << oendl;
109 if (proc == m_rec ) // receive process 165 if (proc == m_rec ) // receive process
110 received(); 166 received();
111 else if ( proc == m_send ) 167 else if ( proc == m_send )
112 sendEnd(); 168 sendEnd();
113 169
114} 170}
115void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ 171void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
116 if ( proc == m_rec ) { // only receive 172 if ( proc == m_rec ) { // only receive
117 QByteArray ar( len ); 173 QByteArray ar( len );
118 memcpy( ar.data(), buf, len ); 174 memcpy( ar.data(), buf, len );
119 m_outp.append( ar ); 175 m_outp.append( ar );
120 } 176 }
121} 177}
122 178
123void BtObex::received() { 179void BtObex::received() {
124 if (m_rec->normalExit() ) { 180 if (m_rec->normalExit() ) {
125 if ( m_rec->exitStatus() == 0 ) { // we got one 181 if ( m_rec->exitStatus() == 0 ) { // we got one
126 QString filename = parseOut(); 182 QString filename = parseOut();
127 emit receivedFile( filename ); 183 emit receivedFile( filename );
128 } 184 }
129 }else{ 185 }else{
130 emit done(false); 186 emit done(false);
131 }; 187 };
132 delete m_rec; 188 delete m_rec;
133 m_rec = 0; 189 m_rec = 0;
134 receive(); 190 receive();
135} 191}
136 192
137void BtObex::sendEnd() { 193void BtObex::sendEnd() {
138 if (m_send->normalExit() ) { 194 if (m_send->normalExit() ) {
139 if ( m_send->exitStatus() == 0 ) { 195 if ( m_send->exitStatus() == 0 ) {
140 delete m_send; 196 delete m_send;
141 m_send=0; 197 m_send=0;
142 emit sent(true); 198 emit sent(true);
143 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 199 }else if (m_send->exitStatus() != 0 ) { // it failed maybe the other side wasn't ready
144 // let's try it again 200 // let's try it again
145 delete m_send; 201 delete m_send;
146 m_send = 0; 202 m_send = 0;
147 sendNow(); 203 sendNow();
148 } 204 }
149 }else { 205 }else {
150 emit error( -1 ); 206 emit error( -1 );
151 delete m_send; 207 delete m_send;
152 m_send = 0; 208 m_send = 0;
153 } 209 }
154} 210}
155 211
156// This probably doesn't do anything useful for bt. 212// This probably doesn't do anything useful for bt.
157QString BtObex::parseOut( ){ 213QString BtObex::parseOut(){
158 QString path; 214 QString path;
159 QStringList list = QStringList::split("\n", m_outp); 215 QStringList list = QStringList::split("\n", m_outp);
160 QStringList::Iterator it; 216 QStringList::Iterator it;
161 for (it = list.begin(); it != list.end(); ++it ) { 217 for (it = list.begin(); it != list.end(); ++it ) {
218 odebug << (*it) << oendl;
162 if ( (*it).startsWith("Wrote" ) ) { 219 if ( (*it).startsWith("Wrote" ) ) {
163 int pos = (*it).findRev('(' ); 220 int pos = (*it).findRev('(' );
164 if ( pos > 0 ) { 221 if ( pos > 0 ) {
165 222
166 path = (*it).remove( pos, (*it).length() - pos ); 223 path = (*it).remove( pos, (*it).length() - pos );
167 path = path.mid(6 ); 224 path = path.mid(6 );
168 path = path.stripWhiteSpace(); 225 path = path.stripWhiteSpace();
169 } 226 }
170 } 227 }
171 } 228 }
172 return path; 229 return path;
173} 230}
174/** 231/**
175 * when sent is done slotError is called we will start receive again 232 * when sent is done slotError is called we will start receive again
176 */ 233 */
177void BtObex::slotError() { 234void BtObex::slotError() {
178 if ( m_receive ) 235 if ( m_receive )
179 receive(); 236 receive();
180}; 237};
181void BtObex::setReceiveEnabled( bool receive ) { 238void BtObex::setReceiveEnabled( bool receive ) {
182 if ( !receive ) { // 239 if ( !receive ) { //
183 m_receive = false; 240 m_receive = false;
184 shutDownReceive(); 241 shutDownReceive();
185 } 242 }
186} 243}
187 244
188void BtObex::shutDownReceive() { 245void BtObex::shutDownReceive() {
189 if (m_rec != 0 ) { 246 if (m_rec != 0 ) {
190 if (m_rec->isRunning() ) { 247 if (m_rec->isRunning() ) {
191 emit error(-1 ); 248 emit error(-1 );
192 delete m_rec; 249 delete m_rec;
193 m_rec = 0; 250 m_rec = 0;
194 } 251 }
195 } 252 }
196 253
197} 254}
diff --git a/core/obex/btobex.h b/core/obex/btobex.h
index 5ab591c..099f04a 100644
--- a/core/obex/btobex.h
+++ b/core/obex/btobex.h
@@ -1,80 +1,86 @@
1 1
2 2
3#ifndef OpieBtObex_H 3#ifndef OpieBtObex_H
4#define OpieBtObex_H 4#define OpieBtObex_H
5 5
6#include <qobject.h> 6#include <qobject.h>
7#include <services.h>
8#include <manager.h>
7 9
8namespace Opie {namespace Core {class OProcess;}} 10namespace Opie {namespace Core {class OProcess;}}
9class QCopChannel; 11class QCopChannel;
12using namespace OpieTooth;
10namespace OpieObex { 13namespace OpieObex {
11 // Maybe this should be derved from Obex. 14 // Maybe this should be derved from Obex.
12 class BtObex : public QObject { 15 class BtObex : public QObject {
13 Q_OBJECT 16 Q_OBJECT
14 public: 17 public:
15 /** 18 /**
16 * BtObex c'tor look 19 * BtObex c'tor look
17 */ 20 */
18 BtObex( QObject *parent, const char* name); 21 BtObex( QObject *parent, const char* name);
19 /** 22 /**
20 * d'tor 23 * d'tor
21 */ 24 */
22 ~BtObex(); 25 ~BtObex();
23 26
24 /** TODO mbhaynie -- Maybe opd would be a better way to receive. 27 /** TODO mbhaynie -- Maybe opd would be a better way to receive.
25 * Starting listening to Bluetooth after enabled by the applet 28 * Starting listening to Bluetooth after enabled by the applet
26 * a signal gets emitted when received a file 29 * a signal gets emitted when received a file
27 */ 30 */
28 void receive(); 31 void receive();
29 void send( const QString&, const QString& ); 32 void send( const QString&, const QString& );
30 void setReceiveEnabled( bool = false ); 33 void setReceiveEnabled( bool = false );
31 signals: 34 signals:
32 35
33 /** 36 /**
34 * a signal 37 * a signal
35 * @param path The path to the received file 38 * @param path The path to the received file
36 */ 39 */
37 void receivedFile( const QString& path); 40 void receivedFile( const QString& path);
38 /** 41 /**
39 * error signal if the program couldn't be started or the 42 * error signal if the program couldn't be started or the
40 * the connection timed out 43 * the connection timed out
41 */ 44 */
42 void error( int ); 45 void error( int );
43 /** 46 /**
44 * The current try to receive data 47 * The current try to receive data
45 */ 48 */
46 void currentTry(unsigned int); 49 void currentTry(unsigned int);
47 /** 50 /**
48 * signal sent The file got beamed to the remote location 51 * signal sent The file got beamed to the remote location
49 */ 52 */
50 void sent(bool); 53 void sent(bool);
51 void done(bool); 54 void done(bool);
52 55
53 private: 56 private:
54 uint m_count; 57 uint m_count;
55 QString m_file; 58 QString m_file;
56 QString m_outp; 59 QString m_outp;
57 QString m_bdaddr; 60 QString m_bdaddr;
61 int m_port;
58 Opie::Core::OProcess *m_send; 62 Opie::Core::OProcess *m_send;
59 Opie::Core::OProcess *m_rec; 63 Opie::Core::OProcess *m_rec;
60 bool m_receive : 1; 64 bool m_receive : 1;
65 OpieTooth::Manager* btManager;
61 void shutDownReceive(); 66 void shutDownReceive();
62 67
63private slots: 68private slots:
64 69
65 // the process exited 70 // the process exited
66 void slotExited(Opie::Core::OProcess* proc) ; 71 void slotExited(Opie::Core::OProcess*) ;
67 void slotStdOut(Opie::Core::OProcess*, char*, int); 72 void slotStdOut(Opie::Core::OProcess*, char*, int);
68 void slotError(); 73 void slotError();
74 void slotFoundServices(const QString&, Services::ValueList);
69 75
70 private: 76 private:
71 void sendNow(); 77 void sendNow();
72 QString parseOut(); 78 QString parseOut();
73 void received(); 79 void received();
74 void sendEnd(); 80 void sendEnd();
75 81
76 }; 82 };
77}; 83};
78 84
79 85
80#endif 86#endif
diff --git a/core/obex/obex.pro b/core/obex/obex.pro
index d6b527c..33cb957 100644
--- a/core/obex/obex.pro
+++ b/core/obex/obex.pro
@@ -1,14 +1,14 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on 2 CONFIG += qt warn_on
3 HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h 3 HEADERS= obex.h btobex.h obexhandler.h obexsend.h receiver.h obeximpl.h
4 SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp 4 SOURCES= obex.cpp btobex.cpp obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp
5 TARGET = opieobex 5 TARGET = opieobex
6 DESTDIR = $(OPIEDIR)/plugins/obex 6 DESTDIR = $(OPIEDIR)/plugins/obex
7INTERFACES = obexsendbase.ui 7INTERFACES = obexsendbase.ui
8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher 8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher $(OPIEDIR)/noncore/net/opietooth/lib
9DEPENDPATH += 9DEPENDPATH +=
10LIBS += -lqpe -lopiecore2 10LIBS += -lopietooth1 -lqpe -lopiecore2
11 VERSION = 0.0.3 11 VERSION = 0.0.3
12 12
13include( $(OPIEDIR)/include.pro ) 13include( $(OPIEDIR)/include.pro )
14target.path = $$prefix/plugins/applets 14target.path = $$prefix/plugins/applets
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index 9cd9972..dbbb7b3 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -1,239 +1,241 @@
1// 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one 1// 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one
2// generated via QT2 Designer. The new form supports 2// generated via QT2 Designer. The new form supports
3// selection of target devices, as opposed to sending to 3// selection of target devices, as opposed to sending to
4// all. 4// all.
5 5
6#include "obex.h" 6#include "obex.h"
7#include "btobex.h" 7#include "btobex.h"
8#include "obexsend.h" 8#include "obexsend.h"
9using namespace OpieObex; 9using namespace OpieObex;
10 10
11/* OPIE */ 11/* OPIE */
12#include <opie2/odebug.h> 12#include <opie2/odebug.h>
13#include <qpe/qcopenvelope_qws.h> 13#include <qpe/qcopenvelope_qws.h>
14#include <qpe/resource.h> 14#include <qpe/resource.h>
15 15
16using namespace Opie::Core; 16using namespace Opie::Core;
17 17
18/* QT */ 18/* QT */
19#include <qlabel.h> 19#include <qlabel.h>
20#include <qpushbutton.h> 20#include <qpushbutton.h>
21#include <qpixmap.h> 21#include <qpixmap.h>
22#include <qlistview.h> 22#include <qlistview.h>
23#include <qtimer.h>
24 23
24#include <unistd.h>
25/* TRANSLATOR OpieObex::SendWidget */ 25/* TRANSLATOR OpieObex::SendWidget */
26 26
27SendWidget::SendWidget( QWidget* parent, const char* name ) 27SendWidget::SendWidget( QWidget* parent, const char* name )
28 : obexSendBase( parent, name ) { 28 : obexSendBase( parent, name ) {
29 initUI(); 29 initUI();
30} 30}
31SendWidget::~SendWidget() { 31SendWidget::~SendWidget() {
32} 32}
33void SendWidget::initUI() { 33void SendWidget::initUI() {
34 m_obex = new Obex(this, "obex"); 34 m_obex = new Obex(this, "obex");
35 connect(m_obex, SIGNAL(error(int) ), 35 connect(m_obex, SIGNAL(error(int) ),
36 this, SLOT(slotIrError(int) ) ); 36 this, SLOT(slotIrError(int) ) );
37 connect(m_obex, SIGNAL(sent(bool) ), 37 connect(m_obex, SIGNAL(sent(bool) ),
38 this, SLOT(slotIrSent(bool) ) ); 38 this, SLOT(slotIrSent(bool) ) );
39 connect(m_obex, SIGNAL(currentTry(unsigned int) ), 39 connect(m_obex, SIGNAL(currentTry(unsigned int) ),
40 this, SLOT(slotIrTry(unsigned int) ) ); 40 this, SLOT(slotIrTry(unsigned int) ) );
41 41
42 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this ); 42 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
43 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 43 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
44 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) ); 44 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) );
45 45
46 m_btobex = new BtObex(this, "btobex"); 46 m_btobex = new BtObex(this, "btobex");
47 connect(m_btobex, SIGNAL(error(int) ), 47 connect(m_btobex, SIGNAL(error(int) ),
48 this, SLOT(slotBtError(int) ) ); 48 this, SLOT(slotBtError(int) ) );
49 connect(m_btobex, SIGNAL(sent(bool) ), 49 connect(m_btobex, SIGNAL(sent(bool) ),
50 this, SLOT(slotBtSent(bool) ) ); 50 this, SLOT(slotBtSent(bool) ) );
51 connect(m_btobex, SIGNAL(currentTry(unsigned int) ), 51 connect(m_btobex, SIGNAL(currentTry(unsigned int) ),
52 this, SLOT(slotBtTry(unsigned int) ) ); 52 this, SLOT(slotBtTry(unsigned int) ) );
53 53
54 chan = new QCopChannel("QPE/BluetoothBack", this ); 54 chan = new QCopChannel("QPE/BluetoothBack", this );
55 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 55 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
56 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) ); 56 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) );
57 57
58} 58}
59 59
60/* 60/*
61 * in send we'll first set everything up 61 * in send we'll first set everything up
62 * and then wait for a list of devices. 62 * and then wait for a list of devices.
63 */ 63 */
64void SendWidget::send( const QString& file, const QString& desc ) { 64void SendWidget::send( const QString& file, const QString& desc ) {
65 m_file = file; 65 m_file = file;
66 m_irDa.clear(); 66 m_irDa.clear();
67 m_start = 0; 67 m_start = 0;
68 68
69 fileToSend->setText(desc.isEmpty() ? file : desc ); 69 fileToSend->setText(desc.isEmpty() ? file : desc );
70 scan_for_receivers(); 70 scan_for_receivers();
71} 71}
72 72
73int SendWidget::addReceiver(const char *r, const char *icon) 73int SendWidget::addReceiver(const char *r, const char *icon)
74{ 74{
75 QListViewItem * item = new QListViewItem( receiverList, 0 ); 75 QListViewItem * item = new QListViewItem( receiverList, 0 );
76 item->setText( 0, r); 76 item->setText( 0, r);
77 item->setPixmap( 1, Resource::loadPixmap( icon ) ); 77 item->setPixmap( 1, Resource::loadPixmap( icon ) );
78 78
79 int id=receivers.count(); 79 int id=receivers.count();
80 receivers[id]=item; 80 receivers[id]=item;
81 return id; 81 return id;
82} 82}
83 83
84bool SendWidget::receiverSelected(int id) 84bool SendWidget::receiverSelected(int id)
85{ 85{
86 return receivers[id]->pixmap(2); 86 return (bool)(receivers[id]->pixmap(2) != NULL);
87} 87}
88 88
89void SendWidget::setReceiverStatus( int id, const QString& status ) { 89void SendWidget::setReceiverStatus( int id, const QString& status ) {
90 if ( !receivers.contains(id) ) return; 90 if ( !receivers.contains(id) ) return;
91 receivers[id]->setText(3, status ); 91 receivers[id]->setText(3, status );
92} 92}
93 93
94void SendWidget::slotIrDaDevices( const QStringList& list) { 94void SendWidget::slotIrDaDevices( const QStringList& list) {
95 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) { 95 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
96 int id = addReceiver(*it, "obex/irda.png"); 96 int id = addReceiver(*it, "obex/irda.png");
97 m_irDa.insert( id, (*it) ); 97 m_irDa.insert( id, (*it) );
98 } 98 }
99 irdaStatus->setText( tr("ready.")); 99 irdaStatus->setText( tr("ready."));
100 m_irDaIt = m_irDa.begin(); 100 m_irDaIt = m_irDa.begin();
101 101
102} 102}
103 103
104void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { 104void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
105 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) { 105 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
106 int id = addReceiver(it.key(), "obex/bt.png"); 106 int id = addReceiver(it.key(), "obex/bt.png");
107 m_bt.insert( id, Pair( it.key(), it.data() ) ); 107 m_bt.insert( id, Pair( it.key(), it.data() ) );
108 } 108 }
109 btStatus->setText(tr("ready.")); 109 btStatus->setText(tr("ready."));
110 m_btIt = m_bt.begin(); 110 m_btIt = m_bt.begin();
111 111
112} 112}
113void SendWidget::slotSelectedDevice( int, int ) { 113void SendWidget::slotSelectedDevice( int, int ) {
114/* if ( name == m_irDeSearch ) { 114/* if ( name == m_irDeSearch ) {
115 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) 115 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
116 m_devBox->removeDevice( it.key() ); 116 m_devBox->removeDevice( it.key() );
117 117
118 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 118 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
119 }*/ 119 }*/
120} 120}
121void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { 121void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
122 if ( str == "devices(QStringList)" ) { 122 if ( str == "devices(QStringList)" ) {
123 QDataStream stream( ar, IO_ReadOnly ); 123 QDataStream stream( ar, IO_ReadOnly );
124 QStringList list; 124 QStringList list;
125 stream >> list; 125 stream >> list;
126 slotIrDaDevices( list ); 126 slotIrDaDevices( list );
127 } 127 }
128} 128}
129void SendWidget::slotIrError( int ) { 129void SendWidget::slotIrError( int ) {
130 irdaStatus->setText(tr("error :(")); 130 irdaStatus->setText(tr("error :("));
131} 131}
132void SendWidget::slotIrSent( bool b) { 132void SendWidget::slotIrSent( bool b) {
133 QString text = b ? tr("Sent") : tr("Failure"); 133 QString text = b ? tr("Sent") : tr("Failure");
134 setReceiverStatus( m_irDaIt.key(), text ); 134 setReceiverStatus( m_irDaIt.key(), text );
135 ++m_irDaIt; 135 ++m_irDaIt;
136 slotStartIrda(); 136 slotStartIrda();
137} 137}
138void SendWidget::slotIrTry(unsigned int trI) { 138void SendWidget::slotIrTry(unsigned int trI) {
139 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); 139 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ));
140} 140}
141void SendWidget::slotStartIrda() { 141void SendWidget::slotStartIrda() {
142 if ( !m_irDa.count() ) return; 142 if ( !m_irDa.count() ) return;
143 if ( m_irDaIt == m_irDa.end() ) { 143 if ( m_irDaIt == m_irDa.end() ) {
144 irdaStatus->setText(tr("complete.")); 144 irdaStatus->setText(tr("complete."));
145 return; 145 return;
146 } 146 }
147 setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); 147 setReceiverStatus( m_irDaIt.key(), tr("Start sending") );
148 m_obex->send( m_file ); 148 m_obex->send( m_file );
149} 149}
150 150
151void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 151void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
152 if ( str == "devices(QStringMap)" ) { 152 if ( str == "devices(QStringMap)" ) {
153 QDataStream stream( ar, IO_ReadOnly ); 153 QDataStream stream( ar, IO_ReadOnly );
154 QMap<QString, QString> btmap; 154 QMap<QString, QString> btmap;
155 stream >> btmap; 155 stream >> btmap;
156 slotBTDevices( btmap ); 156 slotBTDevices( btmap );
157 } 157 }
158} 158}
159void SendWidget::slotBtError( int ) { 159void SendWidget::slotBtError( int ) {
160 btStatus->setText(tr("error :(")); 160 btStatus->setText(tr("error :("));
161} 161}
162void SendWidget::slotBtSent( bool b) { 162void SendWidget::slotBtSent( bool b) {
163 QString text = b ? tr("Sent") : tr("Failure"); 163 QString text = b ? tr("Sent") : tr("Failure");
164 setReceiverStatus( m_btIt.key(), text ); 164 setReceiverStatus( m_btIt.key(), text );
165 ++m_btIt; 165 ++m_btIt;
166 slotStartBt(); 166 slotStartBt();
167} 167}
168void SendWidget::slotBtTry(unsigned int trI) { 168void SendWidget::slotBtTry(unsigned int trI) {
169 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); 169 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
170} 170}
171void SendWidget::slotStartBt() { 171void SendWidget::slotStartBt() {
172 // skip past unselected receivers 172 // skip past unselected receivers
173 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) 173 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key()))
174 ++m_btIt; 174 ++m_btIt;
175 if (m_btIt == m_bt.end() ) { 175 if (m_btIt == m_bt.end() ) {
176 btStatus->setText(tr("complete.")); 176 btStatus->setText(tr("complete."));
177 return; 177 return;
178 } 178 }
179 setReceiverStatus( m_btIt.key(), tr("Start sending") ); 179 setReceiverStatus( m_btIt.key(), tr("Start sending") );
180 m_btobex->send( m_file, m_btIt.data().second() ); 180 m_btobex->send( m_file, m_btIt.data().second() );
181} 181}
182 182
183void SendWidget::send_to_receivers() { 183void SendWidget::send_to_receivers() {
184 slotStartIrda(); 184 slotStartIrda();
185 slotStartBt(); 185 slotStartBt();
186} 186}
187 187
188void SendWidget::scan_for_receivers() 188void SendWidget::scan_for_receivers()
189{ 189{
190 //FIXME: Clean ListBox prior to (re)scan 190 receiverList->clear();
191 receivers.clear();
191 sendButton->setDisabled( true ); 192 sendButton->setDisabled( true );
192 193
193 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) 194 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") )
194 { 195 {
195 irdaStatus->setText(tr("not enabled.")); 196 irdaStatus->setText(tr("not enabled."));
196 } 197 }
197 else 198 else
198 { 199 {
199 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); 200 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()");
200 irdaStatus->setText(tr("searching...")); 201 irdaStatus->setText(tr("searching..."));
201 sendButton->setEnabled( true ); 202 sendButton->setEnabled( true );
202 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 203 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
203 } 204 }
204 205
205 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) 206 if ( !QCopChannel::isRegistered("QPE/Bluetooth") )
206 { 207 {
207 btStatus->setText(tr("not enabled.")); 208 btStatus->setText(tr("not enabled."));
208 } 209 }
209 else 210 else
210 { 211 {
211 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); 212 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
212 btStatus->setText(tr("searching...")); 213 btStatus->setText(tr("searching..."));
213 sendButton->setEnabled( true ); 214 sendButton->setEnabled( true );
214 QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); 215 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
215 } 216 }
216} 217}
217 218
218void SendWidget::toggle_receiver(QListViewItem* item) 219void SendWidget::toggle_receiver(QListViewItem* item)
219{ 220{
220 // toggle the state of an individual receiver. 221 // toggle the state of an individual receiver.
221 if(item->pixmap(2)) 222 if(item->pixmap(2))
222 item->setPixmap(2,QPixmap()); 223 item->setPixmap(2,QPixmap());
223 else 224 else
224 item->setPixmap(2,Resource::loadPixmap("backup/check.png")); 225 item->setPixmap(2,Resource::loadPixmap("backup/check.png"));
225} 226}
226 227
227 228
228void SendWidget::closeEvent( QCloseEvent* e) { 229void SendWidget::closeEvent( QCloseEvent* e) {
229 e->accept(); // make sure 230 obexSendBase::closeEvent(e);
230 QTimer::singleShot(0, this, SLOT(userDone() ) );
231}
232void SendWidget::userDone() {
233 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); 231 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
234 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); 232 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
235 emit done();
236} 233}
234
235void SendWidget::userDone() {
236 close();
237}
238
237QString SendWidget::file()const { 239QString SendWidget::file()const {
238 return m_file; 240 return m_file;
239} 241}