summaryrefslogtreecommitdiff
authorkorovkin <korovkin>2006-07-06 16:28:08 (UTC)
committer korovkin <korovkin>2006-07-06 16:28:08 (UTC)
commit43cd66c08de4447998028179d20fd4817aaf16ca (patch) (unidiff)
tree87888aadc3398c3c633e332cda46d92bb0522d6a
parentadcfc6f4afe184a9eb6fbf458616494dfe0dadda (diff)
downloadopie-43cd66c08de4447998028179d20fd4817aaf16ca.zip
opie-43cd66c08de4447998028179d20fd4817aaf16ca.tar.gz
opie-43cd66c08de4447998028179d20fd4817aaf16ca.tar.bz2
Added OBEX Push functionality for Bluetooth.
- Added ObexBase - asic class for IR and BT Obex - Added ObexServer - OBEX Push server.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/.cvsignore2
-rw-r--r--core/obex/btobex.cpp60
-rw-r--r--core/obex/btobex.h40
-rw-r--r--core/obex/obex.cpp49
-rw-r--r--core/obex/obex.h40
-rw-r--r--core/obex/obex.pro16
-rw-r--r--core/obex/obexbase.cpp74
-rw-r--r--core/obex/obexbase.h99
-rw-r--r--core/obex/obexhandler.cpp44
-rw-r--r--core/obex/obexhandler.h9
-rw-r--r--core/obex/obexsend.cpp2
-rw-r--r--core/obex/obexserver.cpp514
-rw-r--r--core/obex/obexserver.h83
-rw-r--r--core/obex/receiver.cpp9
-rw-r--r--core/obex/receiver.h12
15 files changed, 985 insertions, 68 deletions
diff --git a/core/obex/.cvsignore b/core/obex/.cvsignore
index ed75078..90f9614 100644
--- a/core/obex/.cvsignore
+++ b/core/obex/.cvsignore
@@ -1,4 +1,6 @@
1Makefile 1Makefile
2moc_* 2moc_*
3.moc 3.moc
4.obj 4.obj
5obexsendbase.h
6obexsendbase.cpp
diff --git a/core/obex/btobex.cpp b/core/obex/btobex.cpp
index a5bfe5f..212a084 100644
--- a/core/obex/btobex.cpp
+++ b/core/obex/btobex.cpp
@@ -1,262 +1,294 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Bluetooth OBEX manipulating class implementation
30 */
1 31
2#include "btobex.h" 32#include "btobex.h"
3#include <manager.h> 33#include <manager.h>
4#include <services.h> 34#include <services.h>
5 35
6/* OPIE */ 36/* OPIE */
7#include <opie2/oprocess.h> 37#include <opie2/oprocess.h>
8#include <opie2/odebug.h> 38#include <opie2/odebug.h>
9 39
10/* QT */ 40/* QT */
11#include <qfileinfo.h> 41#include <qfileinfo.h>
12#include <qstring.h> 42#include <qstring.h>
13#include <qmap.h> 43#include <qmap.h>
14#include <qmessagebox.h> 44#include <qmessagebox.h>
15 45
16using namespace OpieObex; 46using namespace OpieObex;
17 47
18using namespace Opie::Core; 48using namespace Opie::Core;
19/* TRANSLATOR OpieObex::Obex */ 49/* TRANSLATOR OpieObex::Obex */
20using namespace OpieTooth; 50using namespace OpieTooth;
21 51
22BtObex::BtObex( QObject *parent, const char* name ) 52BtObex::BtObex( QObject *parent, const char* name )
23 : QObject(parent, name ) 53 : ObexBase(parent, name )
24{ 54{
25 m_rec = 0; 55 m_rec = 0;
26 m_send=0; 56 m_send=0;
27 m_count = 0;
28 m_receive = false;
29 connect( this, SIGNAL(error(int) ), // for recovering to receive
30 SLOT(slotError() ) );
31 connect( this, SIGNAL(sent(bool) ),
32 SLOT(slotError() ) );
33 btManager = NULL; 57 btManager = NULL;
34}; 58};
35 59
36BtObex::~BtObex() { 60BtObex::~BtObex() {
37 delete btManager; 61 delete btManager;
38 delete m_rec; 62 delete m_rec;
39 delete m_send; 63 delete m_send;
40} 64}
41 65
42void BtObex::receive() { 66void BtObex::receive() {
43 m_receive = true; 67 ObexBase::receive();
44 m_outp = QString::null; 68 m_rec = new ObexServer();
45 m_rec = new OProcess();
46 69
70 odebug << "BT OBEX do receive" << oendl;
47 // TODO mbhaynie: No idea if this actually works -- maybe opd is better. 71 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
48 *m_rec << "obexftpd" << "-b";
49 // connect to the necessary slots 72 // connect to the necessary slots
50 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 73 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
51 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 74 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
52 75
53 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 76 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
54 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 77 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
55 78
56 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 79 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
57 emit done( false ); 80 emit done( false );
58 delete m_rec; 81 delete m_rec;
59 m_rec = 0; 82 m_rec = 0;
60 } 83 }
61} 84}
62 85
63void BtObex::send( const QString& fileName, const QString& bdaddr) { 86void BtObex::send( const QString& fileName, const QString& bdaddr) {
87 ObexBase::send(fileName, bdaddr);
64 // if currently receiving stop it send receive 88 // if currently receiving stop it send receive
65 m_count = 0;
66 m_file = fileName;
67 m_bdaddr = bdaddr;
68 if (m_send != 0) { 89 if (m_send != 0) {
69 if (m_send->isSending()) 90 if (m_send->isSending())
70 return; 91 return;
71 else { 92 else {
72 delete m_send; 93 delete m_send;
73 m_send = 0; 94 m_send = 0;
74 } 95 }
75 } 96 }
76 if (m_rec != 0 ) { 97 if (m_rec != 0 ) {
77 if (m_rec->isRunning() ) { 98 if (m_rec->isRunning() ) {
78 emit error(-1 ); 99 emit error(-1 );
79 delete m_rec; 100 delete m_rec;
80 m_rec = 0; 101 m_rec = 0;
81 102
82 }else{ 103 }else{
83 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 104 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
84 return; 105 return;
85 } 106 }
86 } 107 }
87 //Now we need to find out if the OBEX push is supported for this device 108 //Now we need to find out if the OBEX push is supported for this device
88 //And get the port number 109 //And get the port number
89 if (!btManager) { 110 if (!btManager) {
90 btManager = new Manager("hci0"); 111 btManager = new Manager("hci0");
91 connect(btManager, 112 connect(btManager,
92 SIGNAL(foundServices(const QString&, Services::ValueList)), 113 SIGNAL(foundServices(const QString&, Services::ValueList)),
93 this, SLOT(slotFoundServices(const QString&, Services::ValueList))); 114 this, SLOT(slotFoundServices(const QString&, Services::ValueList)));
94 } 115 }
95 btManager->searchServices(bdaddr); 116 btManager->searchServices(bdaddr);
96} 117}
97 118
98/** 119/**
99 * This function reacts on the service discovery finish 120 * This function reacts on the service discovery finish
100 */ 121 */
101void BtObex::slotFoundServices(const QString&, Services::ValueList svcList) 122void BtObex::slotFoundServices(const QString&, Services::ValueList svcList)
102{ 123{
103 QValueList<OpieTooth::Services>::Iterator it; 124 QValueList<OpieTooth::Services>::Iterator it;
104 QMap<int, QString> classList; //The classes list 125 QMap<int, QString> classList; //The classes list
105 QMap<int, QString>::Iterator classIt; //Iterator in the class list 126 QMap<int, QString>::Iterator classIt; //Iterator in the class list
106 int portNum = -1; //The desired port number 127 int portNum = -1; //The desired port number
107 odebug << "BtObex slotFoundServices" << oendl; 128 odebug << "BtObex slotFoundServices" << oendl;
108 if (svcList.isEmpty()) { 129 if (svcList.isEmpty()) {
109 QMessageBox::critical(NULL, tr("Object send"), tr("No services found")); 130 QMessageBox::critical(NULL, tr("Object send"), tr("No services found"));
110 emit error(-1); 131 emit error(-1);
111 return; 132 return;
112 } 133 }
113 for (it = svcList.begin(); it != svcList.end(); it++) { 134 for (it = svcList.begin(); it != svcList.end(); it++) {
114 classList = (*it).classIdList(); 135 classList = (*it).classIdList();
115 classIt = classList.begin(); 136 classIt = classList.begin();
116 if (classIt == classList.end()) 137 if (classIt == classList.end())
117 continue; 138 continue;
118////We really need symbolic names for service IDs 139////We really need symbolic names for service IDs
119 //Ok, we have found the object push service 140 //Ok, we have found the object push service
120 if (classIt.key() == 4357) { 141 if (classIt.key() == 4357) {
121 portNum = (*it).protocolDescriptorList().last().port(); 142 portNum = (*it).protocolDescriptorList().last().port();
122 break; 143 break;
123 } 144 }
124 } 145 }
125 if (portNum == -1) { 146 if (portNum == -1) {
126 QMessageBox::critical(NULL, tr("Object send"), 147 QMessageBox::critical(NULL, tr("Object send"),
127 tr("No OBEX Push service")); 148 tr("No OBEX Push service"));
128 emit error(-1); 149 emit error(-1);
129 return; 150 return;
130 } 151 }
131 m_port = portNum; 152 m_port = portNum;
132 sendNow(); 153 sendNow();
133} 154}
134 155
135void BtObex::sendNow(){ 156void BtObex::sendNow(){
136 QString m_dst = ""; 157 QString m_dst = "";
137 int result; //function call result 158 int result; //function call result
138 if ( m_count >= 25 ) { // could not send 159 if ( m_count >= 25 ) { // could not send
139 emit error(-1 ); 160 emit error(-1 );
140 emit sent(false); 161 emit sent(false);
141 return; 162 return;
142 } 163 }
143 // OProcess inititialisation 164 // OProcess inititialisation
144 m_send = new ObexPush(); 165 m_send = new ObexPush();
145 // connect to slots Exited and and StdOut 166 // connect to slots Exited and and StdOut
146 connect(m_send, SIGNAL(sendComplete(int)), 167 connect(m_send, SIGNAL(sendComplete(int)),
147 this, SLOT(slotPushComplete(int)) ); 168 this, SLOT(slotPushComplete(int)) );
148 connect(m_send, SIGNAL(sendError(int)), 169 connect(m_send, SIGNAL(sendError(int)),
149 this, SLOT(slotPushError(int)) ); 170 this, SLOT(slotPushError(int)) );
150 connect(m_send, SIGNAL(status(QCString&)), 171 connect(m_send, SIGNAL(status(QCString&)),
151 this, SLOT(slotPushStatus(QCString&) ) ); 172 this, SLOT(slotPushStatus(QCString&) ) );
152 173
174 /*
175 * FIXME: this delay is made because some cell phones understands an error
176 * later.
177 */
153 ::sleep(4); 178 ::sleep(4);
154 // now start it 179 // now start it
155 result = m_send->send(m_bdaddr, m_port, m_file, m_dst); 180 result = m_send->send(m_bdaddr, m_port, m_file, m_dst);
156 if (result > 0) //Sending process is actually running 181 if (result > 0) //Sending process is actually running
157 return; 182 return;
158 else if (result < 0) { 183 else if (result < 0) {
159 m_count = 25; 184 m_count = 25;
160 emit error(-1 ); 185 emit error(-1 );
161 delete m_send; 186 delete m_send;
162 m_send=0; 187 m_send=0;
163 } 188 }
164 // end 189 // end
165 m_count++; 190 m_count++;
166 emit currentTry( m_count ); 191 emit currentTry( m_count );
167} 192}
168 193
169void BtObex::slotExited(OProcess* proc ){ 194void BtObex::slotExited(OProcess* proc ){
170 odebug << proc->name() << " exited with result " 195 odebug << proc->name() << " exited with result "
171 << proc->exitStatus() << oendl; 196 << proc->exitStatus() << oendl;
172 if (proc == m_rec ) // receive process 197 if (proc == m_rec ) // receive process
173 received(); 198 received();
199
174} 200}
175void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ 201void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
176 if ( proc == m_rec ) { // only receive 202 if ( proc == m_rec ) { // only receive
177 QByteArray ar( len ); 203 QByteArray ar( len );
178 memcpy( ar.data(), buf, len ); 204 memcpy( ar.data(), buf, len );
179 m_outp.append( ar ); 205 m_outp.append( ar );
206 QCString str(buf, len);
207 odebug << str << oendl;
180 } 208 }
181} 209}
182 210
183void BtObex::slotPushComplete(int result) { 211void BtObex::slotPushComplete(int result) {
184 if (result == 0) { 212 if (result == 0) {
185 delete m_send; 213 delete m_send;
186 m_send=0; 214 m_send=0;
187 emit sent(true); 215 emit sent(true);
188 } else { // it failed maybe the other side wasn't ready 216 } else { // it failed maybe the other side wasn't ready
189 // let's try it again 217 // let's try it again
190 delete m_send; 218 delete m_send;
191 m_send = 0; 219 m_send = 0;
192 sendNow(); 220 sendNow();
193 } 221 }
194} 222}
195 223
196void BtObex::slotPushError(int) { 224void BtObex::slotPushError(int) {
197 emit error( -1 ); 225 emit error( -1 );
198 delete m_send; 226 delete m_send;
199 m_send = 0; 227 m_send = 0;
200} 228}
201 229
202void BtObex::slotPushStatus(QCString& str) { 230void BtObex::slotPushStatus(QCString& str) {
203 odebug << str << oendl; 231 odebug << str << oendl;
204} 232}
205 233
206void BtObex::received() { 234void BtObex::received() {
207 if (m_rec->normalExit() ) { 235 if (m_rec->normalExit() ) {
208 if ( m_rec->exitStatus() == 0 ) { // we got one 236 if ( m_rec->exitStatus() == 0 ) { // we got one
209 QString filename = parseOut(); 237 QString filename = parseOut();
238 odebug << "OBEX " << filename << " received" << oendl;
210 emit receivedFile( filename ); 239 emit receivedFile( filename );
211 } 240 }
212 }else{ 241 }else{
213 emit done(false); 242 emit done(false);
214 }; 243 };
215 delete m_rec; 244 delete m_rec;
216 m_rec = 0; 245 m_rec = 0;
217 receive(); 246 receive();
218} 247}
219 248
220// This probably doesn't do anything useful for bt. 249// This probably doesn't do anything useful for bt.
221QString BtObex::parseOut(){ 250QString BtObex::parseOut(){
222 QString path; 251 QString path;
223 QStringList list = QStringList::split("\n", m_outp); 252 QStringList list = QStringList::split("\n", m_outp);
224 QStringList::Iterator it; 253 QStringList::Iterator it;
225 for (it = list.begin(); it != list.end(); ++it ) { 254 for (it = list.begin(); it != list.end(); ++it ) {
226 odebug << (*it) << oendl; 255 odebug << (*it) << oendl;
227 if ( (*it).startsWith("Wrote" ) ) { 256 if ( (*it).startsWith("Wrote" ) ) {
228 int pos = (*it).findRev('(' ); 257 int pos = (*it).findRev('(' );
229 if ( pos > 0 ) { 258 if ( pos > 0 ) {
230 259
231 path = (*it).remove( pos, (*it).length() - pos ); 260 path = (*it).remove( pos, (*it).length() - pos );
232 path = path.mid(6 ); 261 path = path.mid(6 );
233 path = path.stripWhiteSpace(); 262 path = path.stripWhiteSpace();
234 } 263 }
235 } 264 }
236 } 265 }
237 return path; 266 return path;
238} 267}
239/** 268/**
240 * when sent is done slotError is called we will start receive again 269 * when sent is done slotError is called we will start receive again
241 */ 270 */
242void BtObex::slotError() { 271void BtObex::slotError() {
272 ObexBase::slotError();
243 if ( m_receive ) 273 if ( m_receive )
244 receive(); 274 receive();
245}; 275};
246void BtObex::setReceiveEnabled( bool receive ) { 276void BtObex::setReceiveEnabled( bool receive ) {
277 odebug << "BT OBEX setReceiveEnabled " << receive << oendl;
278 ObexBase::setReceiveEnabled(receive);
247 if ( !receive ) { // 279 if ( !receive ) { //
248 m_receive = false; 280 m_receive = false;
249 shutDownReceive(); 281 shutDownReceive();
250 } 282 }
251} 283}
252 284
253void BtObex::shutDownReceive() { 285void BtObex::shutDownReceive() {
254 if (m_rec != 0 ) { 286 if (m_rec != 0 ) {
255 if (m_rec->isRunning() ) { 287 if (m_rec->isRunning() ) {
256 emit error(-1 ); 288 emit error(-1 );
257 delete m_rec; 289 delete m_rec;
258 m_rec = 0; 290 m_rec = 0;
259 } 291 }
260 } 292 }
261 293
262} 294}
diff --git a/core/obex/btobex.h b/core/obex/btobex.h
index 9c1ab70..7e91c06 100644
--- a/core/obex/btobex.h
+++ b/core/obex/btobex.h
@@ -1,90 +1,118 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Bluetooth OBEX manipulating class declaration
30 */
1 31
2 32
3#ifndef OpieBtObex_H 33#ifndef OpieBtObex_H
4#define OpieBtObex_H 34#define OpieBtObex_H
5 35
36#include "obexbase.h"
6#include <qobject.h> 37#include <qobject.h>
7#include <services.h> 38#include <services.h>
8#include <manager.h> 39#include <manager.h>
9#include <obexpush.h> 40#include <obexpush.h>
41#include "obexserver.h"
10 42
11namespace Opie {namespace Core {class OProcess;}} 43namespace Opie {namespace Core {class OProcess;}}
12class QCopChannel; 44class QCopChannel;
13using namespace OpieTooth; 45using namespace OpieTooth;
14namespace OpieObex { 46namespace OpieObex {
15 // Maybe this should be derved from Obex. 47 // Maybe this should be derved from Obex.
16 class BtObex : public QObject { 48 class BtObex : public ObexBase {
17 Q_OBJECT 49 Q_OBJECT
18 public: 50 public:
19 /** 51 /**
20 * BtObex c'tor look 52 * BtObex c'tor look
21 */ 53 */
22 BtObex( QObject *parent, const char* name); 54 BtObex( QObject *parent, const char* name);
23 /** 55 /**
24 * d'tor 56 * d'tor
25 */ 57 */
26 ~BtObex(); 58 ~BtObex();
27 59
28 /** TODO mbhaynie -- Maybe opd would be a better way to receive. 60 /** TODO mbhaynie -- Maybe opd would be a better way to receive.
29 * Starting listening to Bluetooth after enabled by the applet 61 * Starting listening to Bluetooth after enabled by the applet
30 * a signal gets emitted when received a file 62 * a signal gets emitted when received a file
31 */ 63 */
32 void receive(); 64 void receive();
33 void send( const QString&, const QString& ); 65 void send( const QString&, const QString& );
34 void setReceiveEnabled( bool = false ); 66 void setReceiveEnabled( bool = false );
35 signals: 67 signals:
36 68
37 /** 69 /**
38 * a signal 70 * a signal
39 * @param path The path to the received file 71 * @param path The path to the received file
40 */ 72 */
41 void receivedFile( const QString& path); 73 void receivedFile( const QString& path);
42 /** 74 /**
43 * error signal if the program couldn't be started or the 75 * error signal if the program couldn't be started or the
44 * the connection timed out 76 * the connection timed out
45 */ 77 */
46 void error( int ); 78 void error( int );
47 /** 79 /**
48 * The current try to receive data 80 * The current try to receive data
49 */ 81 */
50 void currentTry(unsigned int); 82 void currentTry(unsigned int);
51 /** 83 /**
52 * signal sent The file got beamed to the remote location 84 * signal sent The file got beamed to the remote location
53 */ 85 */
54 void sent(bool); 86 void sent(bool);
55 void done(bool); 87 void done(bool);
56 88
57 private: 89 private:
58 uint m_count;
59 QString m_file;
60 QString m_outp;
61 QString m_bdaddr;
62 int m_port; 90 int m_port;
63 ObexPush* m_send; 91 ObexPush* m_send;
64 Opie::Core::OProcess *m_rec;
65 bool m_receive : 1; 92 bool m_receive : 1;
66 OpieTooth::Manager* btManager; 93 OpieTooth::Manager* btManager;
67 void shutDownReceive(); 94 void shutDownReceive();
95 ObexServer* m_rec;
68 96
69private slots: 97private slots:
70 98
71 // Push process slots 99 // Push process slots
72 void slotPushStatus(QCString&); 100 void slotPushStatus(QCString&);
73 void slotPushComplete(int); 101 void slotPushComplete(int);
74 void slotPushError(int); 102 void slotPushError(int);
75 103
76 // the process exited 104 // the process exited
77 void slotExited(Opie::Core::OProcess*) ; 105 void slotExited(Opie::Core::OProcess*) ;
78 void slotStdOut(Opie::Core::OProcess*, char*, int); 106 void slotStdOut(Opie::Core::OProcess*, char*, int);
79 void slotError(); 107 void slotError();
80 void slotFoundServices(const QString&, Services::ValueList); 108 void slotFoundServices(const QString&, Services::ValueList);
81 109
82 private: 110 private:
83 void sendNow(); 111 void sendNow();
84 QString parseOut(); 112 QString parseOut();
85 void received(); 113 void received();
86 }; 114 };
87}; 115};
88 116
89 117
90#endif 118#endif
diff --git a/core/obex/obex.cpp b/core/obex/obex.cpp
index 36634ec..95c561a 100644
--- a/core/obex/obex.cpp
+++ b/core/obex/obex.cpp
@@ -1,187 +1,212 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The Infrared OBEX handling class implementation
30 */
1 31
2#include "obex.h" 32#include "obex.h"
3 33
4/* OPIE */ 34/* OPIE */
5#include <opie2/oprocess.h> 35#include <opie2/oprocess.h>
6#include <opie2/odebug.h> 36#include <opie2/odebug.h>
7 37
8/* QT */ 38/* QT */
9#include <qfileinfo.h> 39#include <qfileinfo.h>
10 40
11 41
12 42
13using namespace OpieObex; 43using namespace OpieObex;
14 44
15using namespace Opie::Core; 45using namespace Opie::Core;
16/* TRANSLATOR OpieObex::Obex */ 46/* TRANSLATOR OpieObex::Obex */
17 47
18Obex::Obex( QObject *parent, const char* name ) 48Obex::Obex( QObject *parent, const char* name )
19 : QObject(parent, name ) 49 : ObexBase(parent, name )
20{ 50{
21 m_rec = 0; 51 m_rec = 0;
22 m_send=0; 52 m_send=0;
23 m_count = 0;
24 m_receive = false;
25 connect( this, SIGNAL(error(int) ), // for recovering to receive
26 SLOT(slotError() ) );
27 connect( this, SIGNAL(sent(bool) ),
28 SLOT(slotError() ) );
29}; 53};
30Obex::~Obex() { 54Obex::~Obex() {
31 delete m_rec; 55 delete m_rec;
32 delete m_send; 56 delete m_send;
33} 57}
34void Obex::receive() { 58void Obex::receive() {
35 m_receive = true; 59 ObexBase::receive();
36 m_outp = QString::null;
37 m_rec = new OProcess(); 60 m_rec = new OProcess();
38 *m_rec << "irobex_palm3"; 61 *m_rec << "irobex_palm3";
39 // connect to the necessary slots 62 // connect to the necessary slots
40 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), 63 connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ),
41 this, SLOT(slotExited(Opie::Core::OProcess*) ) ); 64 this, SLOT(slotExited(Opie::Core::OProcess*) ) );
42 65
43 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ), 66 connect(m_rec, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int ) ),
44 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 67 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
45 68
46 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) { 69 if(!m_rec->start(OProcess::NotifyOnExit, OProcess::AllOutput) ) {
47 emit done( false ); 70 emit done( false );
48 delete m_rec; 71 delete m_rec;
49 m_rec = 0; 72 m_rec = 0;
50 } 73 }
51} 74}
52 75
53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 76// if currently receiving stop it send receive
54 m_count = 0; 77void Obex::send(const QString& fileName, const QString& addr) {
55 m_file = fileName; 78 ObexBase::send(fileName, addr);
56 if (m_rec != 0 ) { 79 if (m_rec != 0 ) {
57 if (m_rec->isRunning() ) { 80 if (m_rec->isRunning() ) {
58 emit error(-1 ); 81 emit error(-1 );
59 delete m_rec; 82 delete m_rec;
60 m_rec = 0; 83 m_rec = 0;
61 84
62 }else{ 85 }else{
63 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending 86 emit error( -1 ); // we did not delete yet but it's not running slotExited is pending
64 return; 87 return;
65 } 88 }
66 } 89 }
67 sendNow(); 90 sendNow();
68} 91}
69void Obex::sendNow(){ 92void Obex::sendNow(){
70 if ( m_count >= 25 ) { // could not send 93 if ( m_count >= 25 ) { // could not send
71 emit error(-1 ); 94 emit error(-1 );
72 emit sent(false); 95 emit sent(false);
73 return; 96 return;
74 } 97 }
75 // OProcess inititialisation 98 // OProcess inititialisation
76 m_send = new OProcess(); 99 m_send = new OProcess();
77 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); 100 m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) );
78 101
79 *m_send << "irobex_palm3"; 102 *m_send << "irobex_palm3";
80 *m_send << QFile::encodeName(QFileInfo(m_file).fileName()); 103 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
81 104
82 // connect to slots Exited and and StdOut 105 // connect to slots Exited and and StdOut
83 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), 106 connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ),
84 this, SLOT(slotExited(Opie::Core::OProcess*)) ); 107 this, SLOT(slotExited(Opie::Core::OProcess*)) );
85 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )), 108 connect(m_send, SIGNAL(receivedStdout(Opie::Core::OProcess*, char*, int )),
86 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) ); 109 this, SLOT(slotStdOut(Opie::Core::OProcess*, char*, int) ) );
87 110
88 // now start it 111 // now start it
89 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) { 112 if (!m_send->start(/*OProcess::NotifyOnExit, OProcess::AllOutput*/ ) ) {
90 m_count = 25; 113 m_count = 25;
91 emit error(-1 ); 114 emit error(-1 );
92 delete m_send; 115 delete m_send;
93 m_send=0; 116 m_send=0;
94 } 117 }
95 // end 118 // end
96 m_count++; 119 m_count++;
97 emit currentTry( m_count ); 120 emit currentTry( m_count );
98} 121}
99 122
100void Obex::slotExited(OProcess* proc ){ 123void Obex::slotExited(OProcess* proc ){
101 if (proc == m_rec ) // receive process 124 if (proc == m_rec ) // receive process
102 received(); 125 received();
103 else if ( proc == m_send ) 126 else if ( proc == m_send )
104 sendEnd(); 127 sendEnd();
105 128
106} 129}
107void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 130void Obex::slotStdOut(OProcess* proc, char* buf, int len){
108 if ( proc == m_rec ) { // only receive 131 if ( proc == m_rec ) { // only receive
109 QByteArray ar( len ); 132 QByteArray ar( len );
110 memcpy( ar.data(), buf, len ); 133 memcpy( ar.data(), buf, len );
111 m_outp.append( ar ); 134 m_outp.append( ar );
112 } 135 }
113} 136}
114 137
115void Obex::received() { 138void Obex::received() {
116 if (m_rec->normalExit() ) { 139 if (m_rec->normalExit() ) {
117 if ( m_rec->exitStatus() == 0 ) { // we got one 140 if ( m_rec->exitStatus() == 0 ) { // we got one
118 QString filename = parseOut(); 141 QString filename = parseOut();
119 emit receivedFile( filename ); 142 emit receivedFile( filename );
120 } 143 }
121 }else{ 144 }else{
122 emit done(false); 145 emit done(false);
123 }; 146 };
124 delete m_rec; 147 delete m_rec;
125 m_rec = 0; 148 m_rec = 0;
126 receive(); 149 receive();
127} 150}
128 151
129void Obex::sendEnd() { 152void Obex::sendEnd() {
130 if (m_send->normalExit() ) { 153 if (m_send->normalExit() ) {
131 if ( m_send->exitStatus() == 0 ) { 154 if ( m_send->exitStatus() == 0 ) {
132 delete m_send; 155 delete m_send;
133 m_send=0; 156 m_send=0;
134 emit sent(true); 157 emit sent(true);
135 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready 158 }else if (m_send->exitStatus() == 255 ) { // it failed maybe the other side wasn't ready
136 // let's try it again 159 // let's try it again
137 delete m_send; 160 delete m_send;
138 m_send = 0; 161 m_send = 0;
139 sendNow(); 162 sendNow();
140 } 163 }
141 }else { 164 }else {
142 emit error( -1 ); 165 emit error( -1 );
143 delete m_send; 166 delete m_send;
144 m_send = 0; 167 m_send = 0;
145 } 168 }
146} 169}
147QString Obex::parseOut( ){ 170QString Obex::parseOut( ){
148 QString path; 171 QString path;
149 QStringList list = QStringList::split("\n", m_outp); 172 QStringList list = QStringList::split("\n", m_outp);
150 QStringList::Iterator it; 173 QStringList::Iterator it;
151 for (it = list.begin(); it != list.end(); ++it ) { 174 for (it = list.begin(); it != list.end(); ++it ) {
152 if ( (*it).startsWith("Wrote" ) ) { 175 if ( (*it).startsWith("Wrote" ) ) {
153 int pos = (*it).findRev('(' ); 176 int pos = (*it).findRev('(' );
154 if ( pos > 0 ) { 177 if ( pos > 0 ) {
155 178
156 path = (*it).remove( pos, (*it).length() - pos ); 179 path = (*it).remove( pos, (*it).length() - pos );
157 path = path.mid(6 ); 180 path = path.mid(6 );
158 path = path.stripWhiteSpace(); 181 path = path.stripWhiteSpace();
159 } 182 }
160 } 183 }
161 } 184 }
162 return path; 185 return path;
163} 186}
164/** 187/**
165 * when sent is done slotError is called we will start receive again 188 * when sent is done slotError is called we will start receive again
166 */ 189 */
167void Obex::slotError() { 190void Obex::slotError() {
191 ObexBase::slotError();
168 if ( m_receive ) 192 if ( m_receive )
169 receive(); 193 receive();
170}; 194};
171void Obex::setReceiveEnabled( bool receive ) { 195void Obex::setReceiveEnabled( bool receive ) {
196 ObexBase::setReceiveEnabled(receive);
172 if ( !receive ) { // 197 if ( !receive ) { //
173 m_receive = false; 198 m_receive = false;
174 shutDownReceive(); 199 shutDownReceive();
175 } 200 }
176} 201}
177 202
178void Obex::shutDownReceive() { 203void Obex::shutDownReceive() {
179 if (m_rec != 0 ) { 204 if (m_rec != 0 ) {
180 if (m_rec->isRunning() ) { 205 if (m_rec->isRunning() ) {
181 emit error(-1 ); 206 emit error(-1 );
182 delete m_rec; 207 delete m_rec;
183 m_rec = 0; 208 m_rec = 0;
184 } 209 }
185 } 210 }
186 211
187} 212}
diff --git a/core/obex/obex.h b/core/obex/obex.h
index 5993976..36ff29a 100644
--- a/core/obex/obex.h
+++ b/core/obex/obex.h
@@ -1,84 +1,114 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
1 26
27*/
28/*
29 * The Infrared OBEX handling class declaration
30 */
2 31
3#ifndef OpieObex_H 32#ifndef OpieObex_H
4#define OpieObex_H 33#define OpieObex_H
5 34
35#include "obexbase.h"
6#include <qobject.h> 36#include <qobject.h>
7 37
8namespace Opie {namespace Core {class OProcess;}} 38namespace Opie {namespace Core {class OProcess;}}
9class QCopChannel; 39class QCopChannel;
10namespace OpieObex { 40namespace OpieObex {
11 class Obex : public QObject { 41 class Obex : public ObexBase {
12 Q_OBJECT 42 Q_OBJECT
13 public: 43 public:
14 /** 44 /**
15 * Obex c'tor look 45 * Obex c'tor look
16 */ 46 */
17 Obex( QObject *parent, const char* name); 47 Obex( QObject *parent, const char* name);
18 /** 48 /**
19 * d'tor 49 * d'tor
20 */ 50 */
21 ~Obex(); 51 ~Obex();
22 52
23 /** 53 /**
24 * Starting listening to irda after enabled by the applet 54 * Starting listening to irda after enabled by the applet
25 * a signal gets emitted when received a file 55 * a signal gets emitted when received a file
26 */ 56 */
27 void receive(); 57 virtual void receive();
28 void send( const QString& ); 58 virtual void send(const QString& filename, const QString& addr);
29 void setReceiveEnabled( bool = false ); 59 virtual void setReceiveEnabled( bool = false );
30 signals: 60 signals:
31 61
32 /** 62 /**
33 * a signal 63 * a signal
34 * @param path The path to the received file 64 * @param path The path to the received file
35 */ 65 */
36 void receivedFile( const QString& path); 66 void receivedFile( const QString& path);
37 /** 67 /**
38 * error signal if the program couldn't be started or the 68 * error signal if the program couldn't be started or the
39 * the connection timed out 69 * the connection timed out
40 */ 70 */
41 void error( int ); 71 void error( int );
42 /** 72 /**
43 * The current try to receive data 73 * The current try to receive data
44 */ 74 */
45 void currentTry(unsigned int); 75 void currentTry(unsigned int);
46 /** 76 /**
47 * signal sent The file got beamed to the remote location 77 * signal sent The file got beamed to the remote location
48 */ 78 */
49 void sent(bool); 79 void sent(bool);
50 void done(bool); 80 void done(bool);
51 81
52 private: 82 private:
53 uint m_count; 83 uint m_count;
54 QString m_file; 84 QString m_file;
55 QString m_outp; 85 QString m_outp;
56 Opie::Core::OProcess *m_send; 86 Opie::Core::OProcess *m_send;
57 Opie::Core::OProcess *m_rec; 87 Opie::Core::OProcess *m_rec;
58 bool m_receive : 1; 88 bool m_receive : 1;
59 void shutDownReceive(); 89 void shutDownReceive();
60 90
61private slots: 91private slots:
62 92
63 /** 93 /**
64 * send over palm obex 94 * send over palm obex
65 */ 95 */
66 96
67 //void send(const QString&); 97 //void send(const QString&);
68 98
69 // the process exited 99 // the process exited
70 void slotExited(Opie::Core::OProcess* proc) ; 100 void slotExited(Opie::Core::OProcess* proc) ;
71 void slotStdOut(Opie::Core::OProcess*, char*, int); 101 void slotStdOut(Opie::Core::OProcess*, char*, int);
72 void slotError(); 102 virtual void slotError();
73 103
74 private: 104 private:
75 void sendNow(); 105 void sendNow();
76 QString parseOut(); 106 QString parseOut();
77 void received(); 107 void received();
78 void sendEnd(); 108 void sendEnd();
79 109
80 }; 110 };
81}; 111};
82 112
83 113
84#endif 114#endif
diff --git a/core/obex/obex.pro b/core/obex/obex.pro
index 33cb957..1fc6958 100644
--- a/core/obex/obex.pro
+++ b/core/obex/obex.pro
@@ -1,14 +1,20 @@
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 obexbase.h obexserver.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 obexbase.cpp obexserver.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 $(OPIEDIR)/noncore/net/opietooth/lib 8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher
9DEPENDPATH += 9DEPENDPATH +=
10LIBS += -lopietooth1 -lqpe -lopiecore2 10LIBS += -lqpe -lopiecore2
11 VERSION = 0.0.3 11 VERSION = 0.0.4
12 12
13include( $(OPIEDIR)/include.pro ) 13include( $(OPIEDIR)/include.pro )
14target.path = $$prefix/plugins/applets 14target.path = $$prefix/plugins/applets
15
16#FIXME: These parameters are used if bluetooth is used
17INCLUDEPATH += $(OPIEDIR)/noncore/net/opietooth/lib
18LIBS += -lopietooth1 -lbluetooth -lopenobex
19DEFINES += BLUETOOTH
20
diff --git a/core/obex/obexbase.cpp b/core/obex/obexbase.cpp
new file mode 100644
index 0000000..8eda04e
--- a/dev/null
+++ b/core/obex/obexbase.cpp
@@ -0,0 +1,74 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The basic class for OBEX manipulating classes implementation
30 */
31
32#include "obexbase.h"
33
34/* OPIE */
35#include <opie2/oprocess.h>
36#include <opie2/odebug.h>
37
38using namespace OpieObex;
39
40using namespace Opie::Core;
41
42ObexBase::ObexBase(QObject *parent, const char* name)
43 : QObject(parent, name)
44{
45 m_count = 0;
46 m_receive = false;
47 connect( this, SIGNAL(error(int) ), // for recovering to receive
48 SLOT(slotError() ) );
49 connect( this, SIGNAL(sent(bool) ),
50 SLOT(slotError() ) );
51}
52
53ObexBase::~ObexBase() {
54}
55
56void ObexBase::receive() {
57 m_receive = true;
58 m_outp = QString::null;
59}
60
61void ObexBase::send( const QString& fileName, const QString& bdaddr) {
62 // if currently receiving stop it send receive
63 m_count = 0;
64 m_file = fileName;
65 m_bdaddr = bdaddr;
66}
67
68void ObexBase::setReceiveEnabled(bool) {
69}
70
71void ObexBase::slotError() {
72}
73
74//eof
diff --git a/core/obex/obexbase.h b/core/obex/obexbase.h
new file mode 100644
index 0000000..f65d922
--- a/dev/null
+++ b/core/obex/obexbase.h
@@ -0,0 +1,99 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The basic class for OBEX manipulating classes declaration
30 */
31#ifndef ObexBase_H
32#define ObexBase_H
33
34#include <qobject.h>
35
36namespace Opie {namespace Core {class OProcess;}}
37class QCopChannel;
38namespace OpieObex {
39 class ObexBase : public QObject {
40 Q_OBJECT
41 public:
42 /**
43 * ObexBase constructor look
44 */
45 ObexBase(QObject *parent, const char* name);
46 /**
47 * d'tor
48 */
49 virtual ~ObexBase();
50 /**
51 * Starting listening to an interface after enabled by the applet
52 * a signal gets emitted when received a file
53 */
54 virtual void receive();
55 /**
56 * Send the file
57 * @param the name of the file
58 * @param the address of the device
59 */
60 virtual void send(const QString&, const QString&);
61 /**
62 * Stop receiving
63 * @param if true - does nothing if false - stops receiving
64 */
65 virtual void setReceiveEnabled(bool = false);
66 signals:
67 /**
68 * Notify the upper level that we have received the file
69 * @param path The path to the received file
70 */
71 void receivedFile(const QString& path);
72 /**
73 * error signal if the program couldn't be started or the
74 * the connection timed out
75 */
76 void error(int);
77 /**
78 * The current try to receive data
79 */
80 void currentTry(unsigned int);
81 /**
82 * signal sent The file got beamed to the remote location
83 */
84 void sent(bool);
85 void done(bool);
86 protected:
87 uint m_count;
88 QString m_file;
89 QString m_outp;
90 QString m_bdaddr;
91 bool m_receive : 1;
92 protected slots:
93 virtual void slotError();
94 };
95};
96
97#endif
98//eof
99
diff --git a/core/obex/obexhandler.cpp b/core/obex/obexhandler.cpp
index 28f9b5b..5d98ded 100644
--- a/core/obex/obexhandler.cpp
+++ b/core/obex/obexhandler.cpp
@@ -1,67 +1,79 @@
1 1
2#include <qpe/qcopenvelope_qws.h> 2#include <qpe/qcopenvelope_qws.h>
3#include <qpe/qpeapplication.h> 3#include <qpe/qpeapplication.h>
4 4
5#include "obexsend.h" 5#include "obexsend.h"
6#include "receiver.h" 6#include "receiver.h"
7#include "obexhandler.h" 7#include "obexhandler.h"
8 8
9using namespace OpieObex; 9using namespace OpieObex;
10 10
11/* TRANSLATOR OpieObex::ObexHandler */ 11/* TRANSLATOR OpieObex::ObexHandler */
12 12
13ObexHandler::ObexHandler() { 13ObexHandler::ObexHandler() {
14 m_wasRec = false; 14 m_wasRec[REC_IRDA] = false;
15 m_receiver[REC_IRDA] = 0l;
16 m_wasRec[REC_BLUETOOTH] = false;
17 m_receiver[REC_BLUETOOTH] = 0l;
15 m_sender = 0l; 18 m_sender = 0l;
16 m_receiver = 0l; 19 m_type = REC_IRDA; //FIXME: Just to init to something
17 QCopChannel* chan = new QCopChannel("QPE/Obex"); 20 QCopChannel* chan = new QCopChannel("QPE/Obex");
18 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 21 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
19 this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) ); 22 this, SLOT(irdaMessage(const QCString&,const QByteArray&) ) );
20} 23}
21ObexHandler::~ObexHandler() { 24ObexHandler::~ObexHandler() {
22 delete m_sender; 25 delete m_sender;
23 delete m_receiver; 26 delete m_receiver[REC_IRDA];
27 delete m_receiver[REC_BLUETOOTH];
24} 28}
25void ObexHandler::doSend(const QString& str, const QString& desc) { 29void ObexHandler::doSend(const QString& str, const QString& desc) {
26 delete m_sender; 30 delete m_sender;
27 m_sender = new SendWidget; 31 m_sender = new SendWidget;
28 m_sender->raise(); 32 m_sender->raise();
29 QPEApplication::showWidget( m_sender ); 33 QPEApplication::showWidget( m_sender );
30 connect(m_sender, SIGNAL(done() ), 34 connect(m_sender, SIGNAL(done() ),
31 this, SLOT(slotSent() ) ); 35 this, SLOT(slotSent() ) );
32 m_sender->send( str, desc ); 36 m_sender->send( str, desc );
33} 37}
34void ObexHandler::doReceive(bool b) { 38void ObexHandler::doReceive(RecType type, bool b) {
35 if (m_receiver && b ) return; // we should enable receiver and it is on 39 if (m_receiver[type] && b ) return; // we should enable receiver and it is on
36 else if (!m_receiver && !b ) return; // we should disbale receiver and it is off 40 else if (!m_receiver[type] && !b ) return; // we should disbale receiver and it is off
37 else if (m_receiver && !b ) { 41 else if (m_receiver[type] && !b ) {
38 delete m_receiver; 42 delete m_receiver[type];
39 m_receiver=0; 43 m_receiver[type] = 0;
40 }else if (!m_receiver && b ) { 44 }else if (!m_receiver[type] && b ) {
41 m_receiver= new Receiver; 45 m_receiver[type] = new Receiver(type);
42 } 46 }
43} 47}
44void ObexHandler::slotSent() { 48void ObexHandler::slotSent() {
45 QString file = m_sender->file(); 49 QString file = m_sender->file();
46 delete m_sender; 50 delete m_sender;
47 m_sender = 0; 51 m_sender = 0;
48 QCopEnvelope e ("QPE/Obex", "done(QString)" ); 52 QCopEnvelope e ("QPE/Obex", "done(QString)" );
49 e << file; 53 e << file;
50 doReceive(m_wasRec ); 54 doReceive(REC_IRDA, m_wasRec[REC_IRDA]);
51 m_wasRec = false; 55 doReceive(REC_BLUETOOTH, m_wasRec[REC_BLUETOOTH]);
56 m_wasRec[REC_IRDA] = false;
57 m_wasRec[REC_BLUETOOTH] = false;
52} 58}
53void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) { 59void ObexHandler::irdaMessage( const QCString& msg, const QByteArray& data) {
54 QDataStream stream( data, IO_ReadOnly ); 60 QDataStream stream( data, IO_ReadOnly );
55 if ( msg == "send(QString,QString,QString)" ) { 61 if ( msg == "send(QString,QString,QString)" ) {
56 QString name, desc; 62 QString name, desc;
57 stream >> desc; 63 stream >> desc;
58 stream >> name; 64 stream >> name;
59 m_wasRec = (m_receiver != 0 ); 65 m_wasRec[REC_IRDA] = (m_receiver[REC_IRDA] != 0 );
60 doReceive( false ); 66 m_wasRec[REC_BLUETOOTH] = (m_receiver[REC_BLUETOOTH] != 0 );
67 doReceive(REC_IRDA, false);
68 doReceive(REC_BLUETOOTH, false);
61 doSend(name, desc); 69 doSend(name, desc);
62 }else if (msg == "receive(int)") { 70 }else if (msg == "receive(int)") {
63 int rec; 71 int rec;
64 stream >> rec; 72 stream >> rec;
65 doReceive(rec); 73 doReceive(REC_IRDA, rec);
74 }else if (msg == "btreceive(int)") {
75 int rec;
76 stream >> rec;
77 doReceive(REC_BLUETOOTH, rec);
66 } 78 }
67} 79}
diff --git a/core/obex/obexhandler.h b/core/obex/obexhandler.h
index 230c4f0..de2232e 100644
--- a/core/obex/obexhandler.h
+++ b/core/obex/obexhandler.h
@@ -1,39 +1,40 @@
1#ifndef OPIE_OBEX_HANDLER_H 1#ifndef OPIE_OBEX_HANDLER_H
2#define OPIE_OBEX_HANDLER_H 2#define OPIE_OBEX_HANDLER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qstring.h> 5#include <qstring.h>
6#include "receiver.h"
6 7
7namespace OpieObex { 8namespace OpieObex {
8 /* 9 /*
9 * The handler is responsible for handling receiving 10 * The handler is responsible for handling receiving
10 * and sending 11 * and sending
11 * It will connect to the IrDa QCOP channel and then 12 * It will connect to the IrDa QCOP channel and then
12 * wait for activation... 13 * wait for activation...
13 */ 14 */
14 class SendWidget; 15 class SendWidget;
15 class Receiver; 16 class Receiver;
16 class ObexHandler : public QObject { 17 class ObexHandler : public QObject {
17 Q_OBJECT 18 Q_OBJECT
18 public: 19 public:
19 ObexHandler(); 20 ObexHandler();
20 ~ObexHandler(); 21 ~ObexHandler();
21 22
22 private slots: 23 private slots:
23 void doSend(const QString&,const QString& ); 24 void doSend(const QString&,const QString& );
24 void doReceive(bool b); 25 void doReceive(RecType type, bool b);
25 void slotSent(); 26 void slotSent();
26 27
27 private slots: // QCOP message 28 private slots: // QCOP message
28 void irdaMessage( const QCString&, const QByteArray& ); 29 void irdaMessage( const QCString&, const QByteArray& );
29 30
30 private: 31 private:
31 SendWidget* m_sender; 32 SendWidget* m_sender;
32 Receiver* m_receiver; 33 Receiver* m_receiver[2]; //For IRDA and Bluetooth
33 bool m_wasRec : 1; 34 bool m_wasRec[2];
34 35 RecType m_type; //receiver type (IRDA or Bluetooth)
35 }; 36 };
36} 37}
37 38
38 39
39#endif 40#endif
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
index 8432d16..9a30a0a 100644
--- a/core/obex/obexsend.cpp
+++ b/core/obex/obexsend.cpp
@@ -1,252 +1,252 @@
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 23
24#include <unistd.h> 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 (bool)(receivers[id]->pixmap(2) != NULL); 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(); 95 for (QStringList::ConstIterator it = list.begin();
96 it != list.end(); ++it ) { 96 it != list.end(); ++it ) {
97 int id = addReceiver(*it, "obex/irda.png"); 97 int id = addReceiver(*it, "obex/irda.png");
98 m_irDa.insert( id, (*it) ); 98 m_irDa.insert( id, (*it) );
99 } 99 }
100 irdaStatus->setText( tr("ready.")); 100 irdaStatus->setText( tr("ready."));
101 m_irDaIt = m_irDa.begin(); 101 m_irDaIt = m_irDa.begin();
102 102
103} 103}
104 104
105void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) { 105void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
106 for(QMap<QString, QString>::ConstIterator it = str.begin(); 106 for(QMap<QString, QString>::ConstIterator it = str.begin();
107 it != str.end(); ++it ) { 107 it != str.end(); ++it ) {
108 int id = addReceiver(it.key(), "obex/bt.png"); 108 int id = addReceiver(it.key(), "obex/bt.png");
109 m_bt.insert( id, Pair( it.key(), it.data() ) ); 109 m_bt.insert( id, Pair( it.key(), it.data() ) );
110 } 110 }
111 btStatus->setText(tr("ready.")); 111 btStatus->setText(tr("ready."));
112 m_btIt = m_bt.begin(); 112 m_btIt = m_bt.begin();
113 113
114} 114}
115void SendWidget::slotSelectedDevice( int, int ) { 115void SendWidget::slotSelectedDevice( int, int ) {
116/* if ( name == m_irDeSearch ) { 116/* if ( name == m_irDeSearch ) {
117 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it ) 117 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
118 m_devBox->removeDevice( it.key() ); 118 m_devBox->removeDevice( it.key() );
119 119
120 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 120 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
121 }*/ 121 }*/
122} 122}
123void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) { 123void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
124 if ( str == "devices(QStringList)" ) { 124 if ( str == "devices(QStringList)" ) {
125 QDataStream stream( ar, IO_ReadOnly ); 125 QDataStream stream( ar, IO_ReadOnly );
126 QStringList list; 126 QStringList list;
127 stream >> list; 127 stream >> list;
128 slotIrDaDevices( list ); 128 slotIrDaDevices( list );
129 } 129 }
130} 130}
131void SendWidget::slotIrError( int ) { 131void SendWidget::slotIrError( int ) {
132 irdaStatus->setText(tr("error :(")); 132 irdaStatus->setText(tr("error :("));
133} 133}
134void SendWidget::slotIrSent( bool b) { 134void SendWidget::slotIrSent( bool b) {
135 QString text = b ? tr("Sent") : tr("Failure"); 135 QString text = b ? tr("Sent") : tr("Failure");
136 setReceiverStatus( m_irDaIt.key(), text ); 136 setReceiverStatus( m_irDaIt.key(), text );
137 ++m_irDaIt; 137 ++m_irDaIt;
138 slotStartIrda(); 138 slotStartIrda();
139} 139}
140void SendWidget::slotIrTry(unsigned int trI) { 140void SendWidget::slotIrTry(unsigned int trI) {
141 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) )); 141 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ));
142} 142}
143void SendWidget::slotStartIrda() { 143void SendWidget::slotStartIrda() {
144 if ( !m_irDa.count() ) 144 if ( !m_irDa.count() )
145 return; 145 return;
146 if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) { 146 if ( m_irDaIt == m_irDa.end() || !receiverSelected(m_irDaIt.key())) {
147 irdaStatus->setText(tr("complete.")); 147 irdaStatus->setText(tr("complete."));
148 return; 148 return;
149 } 149 }
150 setReceiverStatus( m_irDaIt.key(), tr("Start sending") ); 150 setReceiverStatus( m_irDaIt.key(), tr("Start sending") );
151 m_obex->send( m_file ); 151 m_obex->send( m_file, tr("noaddress") );
152} 152}
153 153
154void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) { 154void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
155 if ( str == "devices(QStringMap)" ) { 155 if ( str == "devices(QStringMap)" ) {
156 QDataStream stream( ar, IO_ReadOnly ); 156 QDataStream stream( ar, IO_ReadOnly );
157 QMap<QString, QString> btmap; 157 QMap<QString, QString> btmap;
158 stream >> btmap; 158 stream >> btmap;
159 slotBTDevices( btmap ); 159 slotBTDevices( btmap );
160 } 160 }
161} 161}
162void SendWidget::slotBtError( int ) { 162void SendWidget::slotBtError( int ) {
163 btStatus->setText(tr("error :(")); 163 btStatus->setText(tr("error :("));
164} 164}
165void SendWidget::slotBtSent( bool b) { 165void SendWidget::slotBtSent( bool b) {
166 QString text = b ? tr("Sent") : tr("Failure"); 166 QString text = b ? tr("Sent") : tr("Failure");
167 setReceiverStatus( m_btIt.key(), text ); 167 setReceiverStatus( m_btIt.key(), text );
168 ++m_btIt; 168 ++m_btIt;
169 slotStartBt(); 169 slotStartBt();
170} 170}
171void SendWidget::slotBtTry(unsigned int trI) { 171void SendWidget::slotBtTry(unsigned int trI) {
172 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); 172 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
173} 173}
174void SendWidget::slotStartBt() { 174void SendWidget::slotStartBt() {
175 // skip past unselected receivers 175 // skip past unselected receivers
176 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key())) 176 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key()))
177 ++m_btIt; 177 ++m_btIt;
178 if (m_btIt == m_bt.end() ) { 178 if (m_btIt == m_bt.end() ) {
179 btStatus->setText(tr("complete.")); 179 btStatus->setText(tr("complete."));
180 return; 180 return;
181 } 181 }
182 setReceiverStatus( m_btIt.key(), tr("Start sending") ); 182 setReceiverStatus( m_btIt.key(), tr("Start sending") );
183 m_btobex->send( m_file, m_btIt.data().second() ); 183 m_btobex->send( m_file, m_btIt.data().second() );
184} 184}
185 185
186void SendWidget::send_to_receivers() { 186void SendWidget::send_to_receivers() {
187 slotStartIrda(); 187 slotStartIrda();
188 slotStartBt(); 188 slotStartBt();
189} 189}
190 190
191void SendWidget::scan_for_receivers() 191void SendWidget::scan_for_receivers()
192{ 192{
193 receiverList->clear(); 193 receiverList->clear();
194 receivers.clear(); 194 receivers.clear();
195 sendButton->setDisabled( true ); 195 sendButton->setDisabled( true );
196 196
197 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) 197 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") )
198 { 198 {
199 irdaStatus->setText(tr("not enabled.")); 199 irdaStatus->setText(tr("not enabled."));
200 } 200 }
201 else 201 else
202 { 202 {
203 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()"); 203 QCopEnvelope e1("QPE/IrDaApplet", "enableIrda()");
204 irdaStatus->setText(tr("searching...")); 204 irdaStatus->setText(tr("searching..."));
205 sendButton->setEnabled( true ); 205 sendButton->setEnabled( true );
206 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()"); 206 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
207 } 207 }
208 208
209 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) 209 if ( !QCopChannel::isRegistered("QPE/Bluetooth") )
210 { 210 {
211 btStatus->setText(tr("not enabled.")); 211 btStatus->setText(tr("not enabled."));
212 } 212 }
213 else 213 else
214 { 214 {
215 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()"); 215 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
216 btStatus->setText(tr("searching...")); 216 btStatus->setText(tr("searching..."));
217 sendButton->setEnabled( true ); 217 sendButton->setEnabled( true );
218 QCopEnvelope e3("QPE/Bluetooth", "listDevices()"); 218 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
219 } 219 }
220} 220}
221 221
222void SendWidget::toggle_receiver(QListViewItem* item) 222void SendWidget::toggle_receiver(QListViewItem* item)
223{ 223{
224 // toggle the state of an individual receiver. 224 // toggle the state of an individual receiver.
225 if(item->pixmap(2)) 225 if(item->pixmap(2))
226 item->setPixmap(2,QPixmap()); 226 item->setPixmap(2,QPixmap());
227 else 227 else
228 item->setPixmap(2,Resource::loadPixmap("obex/check.png")); 228 item->setPixmap(2,Resource::loadPixmap("obex/check.png"));
229} 229}
230 230
231 231
232void SendWidget::closeEvent( QCloseEvent* evt) { 232void SendWidget::closeEvent( QCloseEvent* evt) {
233 delete m_obex; 233 delete m_obex;
234 m_obex = NULL; 234 m_obex = NULL;
235 delete m_btobex; 235 delete m_btobex;
236 m_btobex = NULL; 236 m_btobex = NULL;
237 obexSendBase::closeEvent(evt); 237 obexSendBase::closeEvent(evt);
238 { 238 {
239 QCopEnvelope e("QPE/IrDaApplet", "disableIrda()"); 239 QCopEnvelope e("QPE/IrDaApplet", "disableIrda()");
240 } 240 }
241 { 241 {
242 QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()"); 242 QCopEnvelope e("QPE/Bluetooth", "disableBluetooth()");
243 } 243 }
244} 244}
245 245
246void SendWidget::userDone() { 246void SendWidget::userDone() {
247 close(); 247 close();
248} 248}
249 249
250QString SendWidget::file()const { 250QString SendWidget::file()const {
251 return m_file; 251 return m_file;
252} 252}
diff --git a/core/obex/obexserver.cpp b/core/obex/obexserver.cpp
new file mode 100644
index 0000000..95196de
--- a/dev/null
+++ b/core/obex/obexserver.cpp
@@ -0,0 +1,514 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The OBEX server class implementation
30 * Based on OBEX server from GPE (thanks, guys)
31 */
32
33#include "obexserver.h"
34#include <unistd.h>
35#include <opie2/odebug.h>
36#include <sys/types.h>
37#include <sys/wait.h>
38#include <errno.h>
39#include <stdlib.h>
40#include <stdio.h>
41#include <fcntl.h>
42#include <qapplication.h>
43#include <opie2/oprocctrl.h>
44#include <qstring.h>
45#include <qfile.h>
46
47using namespace Opie::Core;
48using namespace Opie::Core::Internal;
49using namespace OpieObex;
50
51ObexServer::ObexServer() :
52 OProcess(tr("ObexServer"), 0, "ObexServer")
53{
54 m_obex = NULL;
55}
56
57ObexServer::~ObexServer()
58{
59 stop();
60}
61
62/**
63 * Function handles the file received
64 * @param name the file name
65 * @param data the file data
66 * @param data_len the data length
67 * @return 0 on success -1 on error
68 */
69static int file_received(uint8_t* name, const uint8_t* data, size_t data_len)
70{
71 QString path("/tmp/");
72 path += (char*)name;
73 QFile out(path);
74 int err = 0;
75
76 if (!out.open(IO_Raw | IO_ReadWrite | IO_Truncate)) {
77 printf("File %s open error %d\n", (const char*)path, errno);
78 err = -1;
79 goto out;
80 }
81 if (out.writeBlock((const char*)data, data_len) < 0) {
82 printf("File %s write error %d\n", (const char*)path, errno);
83 err = -1;
84 goto out;
85 }
86out:
87 out.close();
88 if (err == 0) {
89 printf("Wrote %s (%d bytes)\n", (const char*)path, data_len);
90 fflush(stdout);
91 }
92 return err;
93}
94
95/**
96 * Function handles the situation when the PUT request has been done
97 * @param handle OBEX connection handle
98 * @param object OBEX object itself
99 */
100static int put_done(obex_t* handle, obex_object_t* object)
101{
102 obex_headerdata_t hv; //Received file header
103 uint8_t hi; //Type of the request
104 uint32_t hlen; //File (file name) length
105 int err = 0;
106
107 const uint8_t *body = NULL;
108 int body_len = 0;
109 uint8_t* name = NULL;
110
111 while (OBEX_ObjectGetNextHeader (handle, object, &hi, &hv, &hlen)) {
112 switch(hi) {
113 case OBEX_HDR_BODY:
114 body = hv.bs;
115 body_len = hlen;
116 break;
117
118 case OBEX_HDR_NAME:
119 name = new uint8_t[(hlen / 2) + 1];
120 OBEX_UnicodeToChar(name, hv.bs, hlen);
121 break;
122
123 default:
124 break;
125 }
126 }
127
128 if (body)
129 err = file_received(name, body, body_len);
130
131 if (name)
132 delete[] name;
133 return err;
134}
135
136/**
137 * Function handles OBEX request
138 * @param handle OBEX connection handle
139 * @param object OBEX object itself
140 * @param mode
141 * @param event event code
142 * @param cmd OBEX command itself
143 */
144static void handle_request (obex_t* handle, obex_object_t* object,
145 int event, int cmd)
146{
147 (void)event;
148 switch(cmd){
149 case OBEX_CMD_SETPATH:
150 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
151 break;
152 case OBEX_CMD_PUT:
153 if (put_done (handle, object) < 0)
154 OBEX_ObjectSetRsp (object, OBEX_RSP_INTERNAL_SERVER_ERROR,
155 OBEX_RSP_INTERNAL_SERVER_ERROR);
156 else
157 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
158 break;
159 case OBEX_CMD_CONNECT:
160 OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
161 break;
162 case OBEX_CMD_DISCONNECT:
163 OBEX_ObjectSetRsp (object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS);
164 break;
165 default:
166 printf("Denied %02x request\n", cmd);
167 fflush(stdout);
168 OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED,
169 OBEX_RSP_NOT_IMPLEMENTED);
170 break;
171 }
172}
173
174
175/**
176 * Function handles OBEX event when a client is connected to the server
177 * @param handle OBEX connection handle
178 * @param object OBEX object itself
179 * @param mode
180 * @param event event code
181 * @param obex_cmd OBEX command itself
182 * @param obex_rsp OBEX responce
183 */
184static void obex_conn_event (obex_t *handle, obex_object_t *object,
185 int mode, int event, int obex_cmd, int obex_rsp)
186{
187 (void)mode;
188 (void)obex_rsp;
189
190 switch(event) {
191 case OBEX_EV_REQHINT:
192 switch(obex_cmd) {
193 case OBEX_CMD_PUT:
194 case OBEX_CMD_CONNECT:
195 case OBEX_CMD_DISCONNECT:
196 OBEX_ObjectSetRsp (object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
197 break;
198 default:
199 OBEX_ObjectSetRsp (object, OBEX_RSP_NOT_IMPLEMENTED,
200 OBEX_RSP_NOT_IMPLEMENTED);
201 break;
202 }
203 break;
204
205 case OBEX_EV_REQ:
206 /* Comes when a server-request has been received. */
207 handle_request (handle, object, event, obex_cmd);
208 break;
209
210 case OBEX_EV_LINKERR:
211 break;
212 }
213}
214
215/**
216 * Function handles OBEX event
217 * @param handle OBEX connection handle
218 * @param object OBEX object itself
219 * @param mode
220 * @param event event code
221 * @param obex_cmd OBEX command itself
222 * @param obex_rsp OBEX responce
223 */
224static void obex_event (obex_t* handle, obex_object_t* object, int mode,
225 int event, int obex_cmd, int obex_rsp)
226{
227
228 obex_t *obex; //OBEX connection handle
229
230 switch (event) {
231 case OBEX_EV_ACCEPTHINT:
232 obex = OBEX_ServerAccept (handle, obex_conn_event, NULL);
233 break;
234
235 default:
236 obex_conn_event(handle, object, mode, event, obex_cmd, obex_rsp);
237 }
238}
239
240/**
241 * Function registers OBEX push service on a specified channel
242 * Based on The same function from GPE.
243 * @param session SDP session
244 * @param chan channel to listen
245 * @name name to show
246 */
247sdp_session_t* ObexServer::addOpushSvc(uint8_t chan, const char* name)
248{
249 sdp_list_t *svclass_id, *pfseq, *apseq, *root;
250 uuid_t root_uuid, opush_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
251 sdp_profile_desc_t profile[1];
252 sdp_list_t *aproto, *proto[3];
253 sdp_record_t record;
254 sdp_data_t *channel;
255 uint8_t formats[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
256 //uint8_t formats[] = { 0xff };
257 void *dtds[sizeof(formats)], *values[sizeof(formats)];
258 unsigned int i;
259 uint8_t dtd = SDP_UINT8;
260 sdp_data_t *sflist;
261 int err = 0;
262 sdp_session_t* lsession = 0;
263
264 memset((void *)&record, 0, sizeof(sdp_record_t));
265 record.handle = 0xffffffff;
266 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
267 root = sdp_list_append(0, &root_uuid);
268 sdp_set_browse_groups(&record, root);
269
270 sdp_uuid16_create(&opush_uuid, OBEX_OBJPUSH_SVCLASS_ID);
271 svclass_id = sdp_list_append(0, &opush_uuid);
272 sdp_set_service_classes(&record, svclass_id);
273
274 sdp_uuid16_create(&profile[0].uuid, OBEX_OBJPUSH_PROFILE_ID);
275 profile[0].version = 0x0100;
276 pfseq = sdp_list_append(0, profile);
277 sdp_set_profile_descs(&record, pfseq);
278
279 sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
280 proto[0] = sdp_list_append(0, &l2cap_uuid);
281 apseq = sdp_list_append(0, proto[0]);
282
283 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
284 proto[1] = sdp_list_append(0, &rfcomm_uuid);
285 channel = sdp_data_alloc(SDP_UINT8, &chan);
286 proto[1] = sdp_list_append(proto[1], channel);
287 apseq = sdp_list_append(apseq, proto[1]);
288
289 sdp_uuid16_create(&obex_uuid, OBEX_UUID);
290 proto[2] = sdp_list_append(0, &obex_uuid);
291 apseq = sdp_list_append(apseq, proto[2]);
292
293 aproto = sdp_list_append(0, apseq);
294 sdp_set_access_protos(&record, aproto);
295
296 for (i = 0; i < sizeof(formats); i++)
297 {
298 dtds[i] = &dtd;
299 values[i] = &formats[i];
300 }
301 sflist = sdp_seq_alloc(dtds, values, sizeof(formats));
302 sdp_attr_add(&record, SDP_ATTR_SUPPORTED_FORMATS_LIST, sflist);
303
304 sdp_set_info_attr(&record, name, 0, 0);
305
306 // connect to the local SDP server, register the service record, and
307 // disconnect
308 lsession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
309 if (lsession == NULL)
310 goto errout;
311 err = sdp_record_register(lsession, &record, 0);
312 if (err) {
313 sdp_close(lsession);
314 lsession = NULL;
315 }
316errout:
317 sdp_data_free(channel);
318 sdp_list_free(proto[0], 0);
319 sdp_list_free(proto[1], 0);
320 sdp_list_free(proto[2], 0);
321 sdp_list_free(apseq, 0);
322 sdp_list_free(aproto, 0);
323
324 return lsession;
325}
326
327int ObexServer::initObex(void)
328{
329 int channel = 10; //Channel on which we do listen
330 if (m_obex)
331 return 0;
332 m_obex = ::OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, 0);
333 if (!m_obex) {
334 printf("OBEX initialization error %d\n", errno);
335 return -1;
336 }
337 ::BtOBEX_ServerRegister(m_obex, NULL, channel);
338 m_session = addOpushSvc(channel, "OBEX push service");
339 if (!m_session) {
340 printf("OBEX registration error %d\n", errno);
341 ::OBEX_Cleanup(m_obex);
342 m_obex = NULL;
343 return -1;
344 }
345 return 0;
346}
347
348bool ObexServer::start(RunMode runmode, Communication comm)
349{
350 if ( runs )
351 {
352 return false; // cannot start a process that is already running
353 // or if no executable has been assigned
354 }
355 run_mode = runmode;
356 status = 0;
357
358 if ( !setupCommunication( comm ) )
359 qWarning( "Could not setup Communication!" );
360
361 // We do this in the parent because if we do it in the child process
362 // gdb gets confused when the application runs from gdb.
363 uid_t uid = getuid();
364 gid_t gid = getgid();
365#ifdef HAVE_INITGROUPS
366
367 struct passwd *pw = getpwuid( uid );
368#endif
369
370 int fd[ 2 ];
371 if ( 0 > pipe( fd ) )
372 {
373 fd[ 0 ] = fd[ 1 ] = 0; // Pipe failed.. continue
374 }
375
376 runs = true;
377
378 QApplication::flushX();
379
380 // WABA: Note that we use fork() and not vfork() because
381 // vfork() has unclear semantics and is not standardized.
382 pid_ = fork();
383
384 if ( 0 == pid_ )
385 {
386 if ( fd[ 0 ] )
387 close( fd[ 0 ] );
388 if ( !runPrivileged() )
389 {
390 setgid( gid );
391#if defined( HAVE_INITGROUPS)
392
393 if ( pw )
394 initgroups( pw->pw_name, pw->pw_gid );
395#endif
396
397 setuid( uid );
398 }
399 // The child process
400 if ( !commSetupDoneC() )
401 qWarning( "Could not finish comm setup in child!" );
402
403 setupEnvironment();
404
405 // Matthias
406 if ( run_mode == DontCare )
407 setpgid( 0, 0 );
408 // restore default SIGPIPE handler (Harri)
409 struct sigaction act;
410 sigemptyset( &( act.sa_mask ) );
411 sigaddset( &( act.sa_mask ), SIGPIPE );
412 act.sa_handler = SIG_DFL;
413 act.sa_flags = 0;
414 sigaction( SIGPIPE, &act, 0L );
415
416 // We set the close on exec flag.
417 // Closing of fd[1] indicates that the execvp succeeded!
418 if ( fd[ 1 ] )
419 fcntl( fd[ 1 ], F_SETFD, FD_CLOEXEC );
420
421 if (initObex() == 0) {
422 do {
423 int result; //Connection result
424 if ( fd[ 1 ] ) {
425 ::close(fd[1]);
426 fd[1] = 0;
427 }
428 if ((result = OBEX_HandleInput(m_obex, 60)) < 0) {
429 if (errno != ECONNRESET) {
430 printf("OBEX_HandleInput error %d\n", errno);
431 fflush(stdout);
432 _exit(-1);
433 }
434 else
435 _exit(0);
436 }
437 } while(1);
438 }
439 char resultByte = 1;
440 if ( fd[ 1 ] )
441 write( fd[ 1 ], &resultByte, 1 );
442 _exit( -1 );
443 }
444 else if ( -1 == pid_ )
445 {
446 // forking failed
447
448 runs = false;
449 return false;
450 }
451 else
452 {
453 if ( fd[ 1 ] )
454 close( fd[ 1 ] );
455 // the parent continues here
456
457 // Discard any data for stdin that might still be there
458 input_data = 0;
459
460 // Check whether client could be started.
461 if ( fd[ 0 ] )
462 for ( ;; )
463 {
464 char resultByte;
465 int n = ::read( fd[ 0 ], &resultByte, 1 );
466 if ( n == 1 )
467 {
468 // Error
469 runs = false;
470 close( fd[ 0 ] );
471 pid_ = 0;
472 return false;
473 }
474 if ( n == -1 )
475 {
476 if ( ( errno == ECHILD ) || ( errno == EINTR ) )
477 continue; // Ignore
478 }
479 break; // success
480 }
481 if ( fd[ 0 ] )
482 close( fd[ 0 ] );
483
484 if ( !commSetupDoneP() ) // finish communication socket setup for the parent
485 qWarning( "Could not finish comm setup in parent!" );
486
487 if ( run_mode == Block )
488 {
489 commClose();
490
491 // The SIGCHLD handler of the process controller will catch
492 // the exit and set the status
493 while ( runs )
494 {
495 OProcessController::theOProcessController->
496 slotDoHousekeeping( 0 );
497 }
498 runs = FALSE;
499 emit processExited( this );
500 }
501 }
502 return true;
503}
504
505/*
506 * Stop forwarding process
507 */
508int ObexServer::stop()
509{
510 kill(SIGTERM);
511 return 0;
512}
513
514//eof
diff --git a/core/obex/obexserver.h b/core/obex/obexserver.h
new file mode 100644
index 0000000..8567105
--- a/dev/null
+++ b/core/obex/obexserver.h
@@ -0,0 +1,83 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       :
11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28/*
29 * The OBEX server class declaration
30 * Based on OBEX server from GPE (thanks, guys)
31 */
32#ifndef ObexServer_H
33#define ObexServer_H
34
35#include <qobject.h>
36#include <opie2/oprocess.h>
37
38#include <bluetooth/sdp.h>
39#include <bluetooth/sdp_lib.h>
40
41#include <openobex/obex.h>
42
43namespace Opie {
44 namespace Core {
45 class OProcess;
46 namespace Internal {
47 class OProcessController;
48 }
49 }
50};
51
52namespace Opie {namespace Core {class OProcess;}}
53namespace OpieObex {
54 class ObexServer : public Opie::Core::OProcess {
55 Q_OBJECT
56 public:
57 /**
58 * ObexServer constructor
59 */
60 ObexServer();
61 /**
62 *
63 */
64 ~ObexServer();
65 //Function starts the server process
66 virtual bool start( RunMode runmode = NotifyOnExit,
67 Communication comm = NoCommunication );
68 //Stop the server process
69 int stop();
70 protected: //variables
71 obex_t* m_obex; //Obex server handler
72 sdp_session_t* m_session; //SDP session handler;
73 protected: //functions
74 //Funtion initializes obex server return 0 on success and -1 on error
75 int initObex(void);
76 //Function registers an OBEX push service
77 sdp_session_t* addOpushSvc(uint8_t chan, const char* name);
78 signals:
79 protected slots:
80 };
81};
82
83#endif
diff --git a/core/obex/receiver.cpp b/core/obex/receiver.cpp
index 7d9a42a..e153152 100644
--- a/core/obex/receiver.cpp
+++ b/core/obex/receiver.cpp
@@ -1,198 +1,203 @@
1#include "obex.h" 1#include "obex.h"
2#include "btobex.h"
3#include "obexbase.h"
2#include "receiver.h" 4#include "receiver.h"
3using namespace OpieObex; 5using namespace OpieObex;
4 6
5/* OPIE */ 7/* OPIE */
6#include <opie2/odebug.h> 8#include <opie2/odebug.h>
7#include <qpe/applnk.h> 9#include <qpe/applnk.h>
8#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
9#include <qpe/qcopenvelope_qws.h> 11#include <qpe/qcopenvelope_qws.h>
10#include <qpe/filemanager.h> 12#include <qpe/filemanager.h>
11using namespace Opie::Core; 13using namespace Opie::Core;
12 14
13/* QT */ 15/* QT */
14#include <qfileinfo.h> 16#include <qfileinfo.h>
15#include <qlabel.h> 17#include <qlabel.h>
16#include <qtextview.h> 18#include <qtextview.h>
17#include <qpushbutton.h> 19#include <qpushbutton.h>
18 20
19/* STD */ 21/* STD */
20#include <sys/types.h> 22#include <sys/types.h>
21#include <sys/stat.h> 23#include <sys/stat.h>
22#include <sys/mman.h> 24#include <sys/mman.h>
23#include <stdlib.h> // int system 25#include <stdlib.h> // int system
24#include <unistd.h> 26#include <unistd.h>
25#include <fcntl.h> 27#include <fcntl.h>
26 28
27/* TRANSLATOR OpieObex::Receiver */ 29/* TRANSLATOR OpieObex::Receiver */
28 30
29Receiver::Receiver() { 31Receiver::Receiver(RecType type) {
30 m_obex = new Obex(this, "Receiver"); 32 if (type == REC_IRDA)
33 m_obex = new Obex(this, "Receiver");
34 else
35 m_obex = new BtObex(this, "Receiver");
31 connect(m_obex, SIGNAL(receivedFile(const QString&) ), 36 connect(m_obex, SIGNAL(receivedFile(const QString&) ),
32 this, SLOT(slotReceived(const QString&) ) ); 37 this, SLOT(slotReceived(const QString&) ) );
33 m_obex->receive(); 38 m_obex->receive();
34} 39}
35Receiver::~Receiver() { 40Receiver::~Receiver() {
36 m_obex->setReceiveEnabled( false ); 41 m_obex->setReceiveEnabled( false );
37 delete m_obex; 42 delete m_obex;
38} 43}
39void Receiver::slotReceived( const QString& _file ) { 44void Receiver::slotReceived( const QString& _file ) {
40 QString file = _file; 45 QString file = _file;
41 int check = checkFile(file); 46 int check = checkFile(file);
42 if ( check == AddressBook ) 47 if ( check == AddressBook )
43 handleAddr( file ); 48 handleAddr( file );
44 else if ( check == Datebook ) 49 else if ( check == Datebook )
45 handleDateTodo( file ); 50 handleDateTodo( file );
46 else 51 else
47 handleOther( file ); 52 handleOther( file );
48} 53}
49void Receiver::handleAddr( const QString& str ) { 54void Receiver::handleAddr( const QString& str ) {
50 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" ); 55 QCopEnvelope e("QPE/Application/addressbook", "setDocument(QString)" );
51 e << str; 56 e << str;
52} 57}
53/* we can not say for sure if it's a VEevent ot VTodo */ 58/* we can not say for sure if it's a VEevent ot VTodo */
54void Receiver::handleDateTodo( const QString& str ) { 59void Receiver::handleDateTodo( const QString& str ) {
55 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)"); 60 QCopEnvelope e0("QPE/Application/todolist", "setDocument(QString)");
56 e0 << str; 61 e0 << str;
57 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" ); 62 QCopEnvelope e1("QPE/Application/datebook", "setDocument(QString)" );
58 e1 << str; 63 e1 << str;
59} 64}
60/* 65/*
61 * Handle other asks if it should accept the 66 * Handle other asks if it should accept the
62 * beamed object and creates a DocLnk 67 * beamed object and creates a DocLnk
63 */ 68 */
64void Receiver::handleOther( const QString& other ) { 69void Receiver::handleOther( const QString& other ) {
65 OtherHandler* hand = new OtherHandler(); 70 OtherHandler* hand = new OtherHandler();
66 hand->handle( other ); 71 hand->handle( other );
67} 72}
68void Receiver::tidyUp( QString& _file, const QString& ending) { 73void Receiver::tidyUp( QString& _file, const QString& ending) {
69 /* libversit fails on BASE64 encoding we try to sed it away */ 74 /* libversit fails on BASE64 encoding we try to sed it away */
70 QString file = _file; 75 QString file = _file;
71 char foo[24]; // big enough 76 char foo[24]; // big enough
72 (void)::strcpy(foo, "/tmp/opie-XXXXXX"); 77 (void)::strcpy(foo, "/tmp/opie-XXXXXX");
73 78
74 int fd = ::mkstemp(foo); 79 int fd = ::mkstemp(foo);
75 80
76 if ( fd == -1 ) 81 if ( fd == -1 )
77 return; 82 return;
78 83
79 (void)::strncat( foo, QFile::encodeName(ending), 4 ); 84 (void)::strncat( foo, QFile::encodeName(ending), 4 );
80 _file = QString::fromLocal8Bit( foo ); 85 _file = QString::fromLocal8Bit( foo );
81 QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) ); 86 QString cmd = QString("sed -e \"s/^\\(X-MICROSOFT-BODYINK\\)\\;/\\1:/;\" < %2 > %2 ").arg( Global::shellQuote(file)).arg( Global::shellQuote(_file) );
82 (void)::system( QFile::encodeName(cmd) ); 87 (void)::system( QFile::encodeName(cmd) );
83 88
84 cmd = QString("rm %1").arg( Global::shellQuote(file) ); 89 cmd = QString("rm %1").arg( Global::shellQuote(file) );
85 (void)::system( QFile::encodeName(cmd) ); 90 (void)::system( QFile::encodeName(cmd) );
86} 91}
87int Receiver::checkFile( QString& file ) { 92int Receiver::checkFile( QString& file ) {
88 int ret; 93 int ret;
89 QString ending; 94 QString ending;
90 95
91 if (file.right(4) == ".vcs" ) { 96 if (file.right(4) == ".vcs" ) {
92 ret = Datebook; 97 ret = Datebook;
93 ending = QString::fromLatin1(".vcs"); 98 ending = QString::fromLatin1(".vcs");
94 }else if ( file.right(4) == ".vcf") { 99 }else if ( file.right(4) == ".vcf") {
95 ret = AddressBook; 100 ret = AddressBook;
96 ending = QString::fromLatin1(".vcf"); 101 ending = QString::fromLatin1(".vcf");
97 }else 102 }else
98 ret = Other; 103 ret = Other;
99 104
100 105
101 if (ending.isEmpty() ) 106 if (ending.isEmpty() )
102 return ret; 107 return ret;
103 108
104 /** 109 /**
105 * currently the parser is broken in regard of BASE64 encoding 110 * currently the parser is broken in regard of BASE64 encoding
106 * and M$ likes to send that. So we will executed a small 111 * and M$ likes to send that. So we will executed a small
107 * tidy up system sed script 112 * tidy up system sed script
108 * At this point we can also remove umlaute from the filename 113 * At this point we can also remove umlaute from the filename
109 */ 114 */
110 tidyUp( file, ending ); 115 tidyUp( file, ending );
111 116
112 return ret; 117 return ret;
113} 118}
114 119
115/* TRANSLATOR OpieObex::OtherHandler */ 120/* TRANSLATOR OpieObex::OtherHandler */
116 121
117OtherHandler::OtherHandler() 122OtherHandler::OtherHandler()
118 : QVBox() 123 : QVBox()
119{ 124{
120 QHBox* box = new QHBox(this); 125 QHBox* box = new QHBox(this);
121 QLabel* lbl = new QLabel(box); 126 QLabel* lbl = new QLabel(box);
122 lbl->setText(tr("<qt><b>Received:</b></qt>")); 127 lbl->setText(tr("<qt><b>Received:</b></qt>"));
123 m_na = new QLabel(box); 128 m_na = new QLabel(box);
124 129
125 QFrame* frame = new QFrame(this); 130 QFrame* frame = new QFrame(this);
126 frame->setFrameShape( QFrame::HLine ); 131 frame->setFrameShape( QFrame::HLine );
127 frame->setFrameShadow( QFrame::Sunken ); 132 frame->setFrameShadow( QFrame::Sunken );
128 133
129 m_view = new QTextView(this); 134 m_view = new QTextView(this);
130 135
131 box = new QHBox(this); 136 box = new QHBox(this);
132 QPushButton *but = new QPushButton(box); 137 QPushButton *but = new QPushButton(box);
133 but->setText(tr("Accept") ); 138 but->setText(tr("Accept") );
134 connect(but, SIGNAL(clicked() ), 139 connect(but, SIGNAL(clicked() ),
135 this, SLOT(accept()) ); 140 this, SLOT(accept()) );
136 141
137 but = new QPushButton(box); 142 but = new QPushButton(box);
138 but->setText(tr("Deny") ); 143 but->setText(tr("Deny") );
139 connect(but, SIGNAL(clicked() ), 144 connect(but, SIGNAL(clicked() ),
140 this, SLOT(deny() ) ); 145 this, SLOT(deny() ) );
141 146
142 raise(); 147 raise();
143 showMaximized(); 148 showMaximized();
144} 149}
145OtherHandler::~OtherHandler() { 150OtherHandler::~OtherHandler() {
146 151
147} 152}
148void OtherHandler::handle( const QString& file ) { 153void OtherHandler::handle( const QString& file ) {
149 m_file = file; 154 m_file = file;
150 m_na->setText(file); 155 m_na->setText(file);
151 DocLnk lnk(file); 156 DocLnk lnk(file);
152 157
153 QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() ); 158 QString str = tr("<p>You received a file of type %1 (<img src=\"%2\"> )What do you want to do?").arg(lnk.type() ).arg(lnk.icon() );
154 m_view->setText( str ); 159 m_view->setText( str );
155} 160}
156 161
157/* 162/*
158 * hehe evil evil mmap ahead :) 163 * hehe evil evil mmap ahead :)
159 * we quickly copy the file and then we'll create a DocLnk for it 164 * we quickly copy the file and then we'll create a DocLnk for it
160 */ 165 */
161void OtherHandler::accept() { 166void OtherHandler::accept() {
162 QString na = targetName( m_file ); 167 QString na = targetName( m_file );
163 copy(m_file, na ); 168 copy(m_file, na );
164 DocLnk lnk(na); 169 DocLnk lnk(na);
165 lnk.writeLink(); 170 lnk.writeLink();
166 QFile::remove(m_file); 171 QFile::remove(m_file);
167 delete this; 172 delete this;
168} 173}
169void OtherHandler::deny() { 174void OtherHandler::deny() {
170 QFile::remove( m_file ); 175 QFile::remove( m_file );
171 delete this; 176 delete this;
172} 177}
173QString OtherHandler::targetName( const QString& file ) { 178QString OtherHandler::targetName( const QString& file ) {
174 QFileInfo info( file ); 179 QFileInfo info( file );
175 180
176 /* $HOME needs to be set!!!! */ 181 /* $HOME needs to be set!!!! */
177 Global::createDocDir(); 182 Global::createDocDir();
178 183
179 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName(); 184 QString newFile = QPEApplication::documentDir()+ "/"+ info.baseName();
180 QString newFileBase = newFile; 185 QString newFileBase = newFile;
181 186
182 int trie = 0; 187 int trie = 0;
183 while (QFile::exists(newFile + "."+info.extension() ) ) { 188 while (QFile::exists(newFile + "."+info.extension() ) ) {
184 newFile = newFileBase + "_"+QString::number(trie) ; 189 newFile = newFileBase + "_"+QString::number(trie) ;
185 trie++; 190 trie++;
186 } 191 }
187 newFile += "." + info.extension(); 192 newFile += "." + info.extension();
188 193
189 return newFile; 194 return newFile;
190} 195}
191 196
192/* fast cpy */ 197/* fast cpy */
193void OtherHandler::copy(const QString& src, const QString& file) { 198void OtherHandler::copy(const QString& src, const QString& file) {
194 FileManager *fm; 199 FileManager *fm;
195 if(!fm->copyFile(src,file)) { 200 if(!fm->copyFile(src,file)) {
196 owarn << "Copy failed" << oendl; 201 owarn << "Copy failed" << oendl;
197 } 202 }
198} 203}
diff --git a/core/obex/receiver.h b/core/obex/receiver.h
index e1d54df..a10ea13 100644
--- a/core/obex/receiver.h
+++ b/core/obex/receiver.h
@@ -1,58 +1,64 @@
1#ifndef OPIE_OBEX_RECEIVER_H 1#ifndef OPIE_OBEX_RECEIVER_H
2#define OPIE_OBEX_RECEIVER_H 2#define OPIE_OBEX_RECEIVER_H
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include <qvbox.h> 5#include <qvbox.h>
6#include <qstring.h> 6#include <qstring.h>
7 7
8//Receiver type
9typedef enum _RecType {
10 REC_IRDA = 0,
11 REC_BLUETOOTH = 1
12} RecType;
13
8class QLabel; 14class QLabel;
9class QTextView; 15class QTextView;
10namespace OpieObex { 16namespace OpieObex {
11 class Obex; 17 class ObexBase;
12 class OtherHandler; 18 class OtherHandler;
13 class Receiver : public QObject { 19 class Receiver : public QObject {
14 Q_OBJECT 20 Q_OBJECT
15 public: 21 public:
16 enum { Datebook , AddressBook, Other }; 22 enum { Datebook , AddressBook, Other };
17 Receiver(); 23 Receiver(RecType type);
18 ~Receiver(); 24 ~Receiver();
19 25
20 private: 26 private:
21 void handleAddr(const QString& ); 27 void handleAddr(const QString& );
22 void handleDateTodo(const QString& ); 28 void handleDateTodo(const QString& );
23 void handleOther(const QString& ); 29 void handleOther(const QString& );
24 /* will alter the file name */ 30 /* will alter the file name */
25 int checkFile( QString& file ); 31 int checkFile( QString& file );
26 bool testDateTodo(const QString& file); 32 bool testDateTodo(const QString& file);
27 bool testAddressbook(const QString& file); 33 bool testAddressbook(const QString& file);
28 /* called by checkFile */ 34 /* called by checkFile */
29 void tidyUp( QString& file, const QString& ending ); 35 void tidyUp( QString& file, const QString& ending );
30 36
31 private slots: 37 private slots:
32 void slotReceived( const QString& ); 38 void slotReceived( const QString& );
33 39
34 private: 40 private:
35 Obex* m_obex; 41 ObexBase* m_obex; //IR obex
36 }; 42 };
37 43
38 class OtherHandler : public QVBox { 44 class OtherHandler : public QVBox {
39 Q_OBJECT 45 Q_OBJECT
40 public: 46 public:
41 OtherHandler(); 47 OtherHandler();
42 ~OtherHandler(); 48 ~OtherHandler();
43 49
44 void handle( const QString& file ); 50 void handle( const QString& file );
45 private slots: 51 private slots:
46 void accept(); 52 void accept();
47 void deny(); 53 void deny();
48 private: 54 private:
49 QString targetName( const QString& file ); 55 QString targetName( const QString& file );
50 void copy( const QString& src, const QString& dest ); 56 void copy( const QString& src, const QString& dest );
51 QLabel* m_na; 57 QLabel* m_na;
52 QTextView* m_view; 58 QTextView* m_view;
53 QString m_file; 59 QString m_file;
54 }; 60 };
55} 61}
56 62
57 63
58#endif 64#endif