summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/btobex.cpp (renamed from core/obex/obex.cc)42
-rw-r--r--core/obex/btobex.h (renamed from core/obex/obex.h)26
-rw-r--r--core/obex/obex.pro10
-rw-r--r--core/obex/obexsend.cpp289
-rw-r--r--core/obex/obexsend.h125
5 files changed, 42 insertions, 450 deletions
diff --git a/core/obex/obex.cc b/core/obex/btobex.cpp
index 36634ec..a2866f6 100644
--- a/core/obex/obex.cc
+++ b/core/obex/btobex.cpp
@@ -1,3 +1,3 @@
1 1
2#include "obex.h" 2#include "btobex.h"
3 3
@@ -17,3 +17,3 @@ using namespace Opie::Core;
17 17
18Obex::Obex( QObject *parent, const char* name ) 18BtObex::BtObex( QObject *parent, const char* name )
19 : QObject(parent, name ) 19 : QObject(parent, name )
@@ -29,3 +29,3 @@ Obex::Obex( QObject *parent, const char* name )
29}; 29};
30Obex::~Obex() { 30BtObex::~BtObex() {
31 delete m_rec; 31 delete m_rec;
@@ -33,3 +33,3 @@ Obex::~Obex() {
33} 33}
34void Obex::receive() { 34void BtObex::receive() {
35 m_receive = true; 35 m_receive = true;
@@ -37,3 +37,5 @@ void Obex::receive() {
37 m_rec = new OProcess(); 37 m_rec = new OProcess();
38 *m_rec << "irobex_palm3"; 38
39 // TODO mbhaynie: No idea if this actually works -- maybe opd is better.
40 *m_rec << "obexftpd" << "-b";
39 // connect to the necessary slots 41 // connect to the necessary slots
@@ -52,5 +54,7 @@ void Obex::receive() {
52 54
53void Obex::send( const QString& fileName) { // if currently receiving stop it send receive 55void BtObex::send( const QString& fileName, const QString& bdaddr) {
56 // if currently receiving stop it send receive
54 m_count = 0; 57 m_count = 0;
55 m_file = fileName; 58 m_file = fileName;
59 m_bdaddr = bdaddr;
56 if (m_rec != 0 ) { 60 if (m_rec != 0 ) {
@@ -68,3 +72,3 @@ void Obex::send( const QString& fileName) { // if currently receiving stop it se
68} 72}
69void Obex::sendNow(){ 73void BtObex::sendNow(){
70 if ( m_count >= 25 ) { // could not send 74 if ( m_count >= 25 ) { // could not send
@@ -78,4 +82,8 @@ void Obex::sendNow(){
78 82
79 *m_send << "irobex_palm3"; 83 // obextool push file <bdaddr> [channel]
84 // 9 for phones.
85 // Palm T3 accepts pictures on 1
86 *m_send << "obextool" << "push";
80 *m_send << QFile::encodeName(QFileInfo(m_file).fileName()); 87 *m_send << QFile::encodeName(QFileInfo(m_file).fileName());
88 *m_send << m_bdaddr << "9";
81 89
@@ -99,3 +107,3 @@ void Obex::sendNow(){
99 107
100void Obex::slotExited(OProcess* proc ){ 108void BtObex::slotExited(OProcess* proc ){
101 if (proc == m_rec ) // receive process 109 if (proc == m_rec ) // receive process
@@ -106,3 +114,3 @@ void Obex::slotExited(OProcess* proc ){
106} 114}
107void Obex::slotStdOut(OProcess* proc, char* buf, int len){ 115void BtObex::slotStdOut(OProcess* proc, char* buf, int len){
108 if ( proc == m_rec ) { // only receive 116 if ( proc == m_rec ) { // only receive
@@ -114,3 +122,3 @@ void Obex::slotStdOut(OProcess* proc, char* buf, int len){
114 122
115void Obex::received() { 123void BtObex::received() {
116 if (m_rec->normalExit() ) { 124 if (m_rec->normalExit() ) {
@@ -128,3 +136,3 @@ void Obex::received() {
128 136
129void Obex::sendEnd() { 137void BtObex::sendEnd() {
130 if (m_send->normalExit() ) { 138 if (m_send->normalExit() ) {
@@ -146,3 +154,5 @@ void Obex::sendEnd() {
146} 154}
147QString Obex::parseOut( ){ 155
156// This probably doesn't do anything useful for bt.
157QString BtObex::parseOut( ){
148 QString path; 158 QString path;
@@ -166,3 +176,3 @@ QString Obex::parseOut( ){
166 */ 176 */
167void Obex::slotError() { 177void BtObex::slotError() {
168 if ( m_receive ) 178 if ( m_receive )
@@ -170,3 +180,3 @@ void Obex::slotError() {
170}; 180};
171void Obex::setReceiveEnabled( bool receive ) { 181void BtObex::setReceiveEnabled( bool receive ) {
172 if ( !receive ) { // 182 if ( !receive ) { //
@@ -177,3 +187,3 @@ void Obex::setReceiveEnabled( bool receive ) {
177 187
178void Obex::shutDownReceive() { 188void BtObex::shutDownReceive() {
179 if (m_rec != 0 ) { 189 if (m_rec != 0 ) {
diff --git a/core/obex/obex.h b/core/obex/btobex.h
index 5993976..5ab591c 100644
--- a/core/obex/obex.h
+++ b/core/obex/btobex.h
@@ -2,4 +2,4 @@
2 2
3#ifndef OpieObex_H 3#ifndef OpieBtObex_H
4#define OpieObex_H 4#define OpieBtObex_H
5 5
@@ -10,3 +10,4 @@ class QCopChannel;
10namespace OpieObex { 10namespace OpieObex {
11 class Obex : public QObject { 11 // Maybe this should be derved from Obex.
12 class BtObex : public QObject {
12 Q_OBJECT 13 Q_OBJECT
@@ -14,5 +15,5 @@ namespace OpieObex {
14 /** 15 /**
15 * Obex c'tor look 16 * BtObex c'tor look
16 */ 17 */
17 Obex( QObject *parent, const char* name); 18 BtObex( QObject *parent, const char* name);
18 /** 19 /**
@@ -20,6 +21,6 @@ namespace OpieObex {
20 */ 21 */
21 ~Obex(); 22 ~BtObex();
22 23
23 /** 24 /** TODO mbhaynie -- Maybe opd would be a better way to receive.
24 * Starting listening to irda after enabled by the applet 25 * Starting listening to Bluetooth after enabled by the applet
25 * a signal gets emitted when received a file 26 * a signal gets emitted when received a file
@@ -27,3 +28,3 @@ namespace OpieObex {
27 void receive(); 28 void receive();
28 void send( const QString& ); 29 void send( const QString&, const QString& );
29 void setReceiveEnabled( bool = false ); 30 void setReceiveEnabled( bool = false );
@@ -55,2 +56,3 @@ namespace OpieObex {
55 QString m_outp; 56 QString m_outp;
57 QString m_bdaddr;
56 Opie::Core::OProcess *m_send; 58 Opie::Core::OProcess *m_send;
@@ -62,8 +64,2 @@ private slots:
62 64
63 /**
64 * send over palm obex
65 */
66
67 //void send(const QString&);
68
69 // the process exited 65 // the process exited
diff --git a/core/obex/obex.pro b/core/obex/obex.pro
index 4e72bc4..1f4f486 100644
--- a/core/obex/obex.pro
+++ b/core/obex/obex.pro
@@ -2,10 +2,10 @@ TEMPLATE = lib
2 CONFIG += qt warn_on 2 CONFIG += qt warn_on
3 HEADERS= obex.h obexhandler.h obexsend.h receiver.h obeximpl.h 3 HEADERS = btobex.h obexhandler.h receiver.h obeximpl.h
4 SOURCES= obex.cc obexsend.cpp obexhandler.cpp receiver.cpp obeximpl.cpp 4 SOURCES = btobex.cpp obexhandler.cpp receiver.cpp obeximpl.cpp
5 TARGET = opieobex 5 TARGET = opieobex
6 DESTDIR = $(OPIEDIR)/plugins/obex 6 DESTDIR = $(OPIEDIR)/plugins/obex
7INTERFACES = obexsendbase.ui
7INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher 8INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher
8DEPENDPATH += 9 LIBS += -lqpe -lopiecore2
9LIBS += -lqpe -lopiecore2 10 VERSION = 0.0.3
10 VERSION = 0.0.2
11 11
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
deleted file mode 100644
index 675c5e4..0000000
--- a/core/obex/obexsend.cpp
+++ b/dev/null
@@ -1,289 +0,0 @@
1#include "obex.h"
2#include "obexsend.h"
3using namespace OpieObex;
4
5/* OPIE */
6#include <opie2/odebug.h>
7#include <qpe/qcopenvelope_qws.h>
8using namespace Opie::Core;
9
10/* QT */
11#include <qpushbutton.h>
12#include <qlabel.h>
13#include <qlayout.h>
14#include <qtimer.h>
15
16/* TRANSLATOR OpieObex::SendWidget */
17
18SendWidget::SendWidget( QWidget* parent, const char* name )
19 : QWidget( parent, name ) {
20 initUI();
21}
22SendWidget::~SendWidget() {
23}
24void SendWidget::initUI() {
25 m_obex = new Obex(this, "obex");
26 connect(m_obex, SIGNAL(error(int) ),
27 this, SLOT(slotIrError(int) ) );
28 connect(m_obex, SIGNAL(sent(bool) ),
29 this, SLOT(slotIrSent(bool) ) );
30 connect(m_obex, SIGNAL(currentTry(unsigned int) ),
31 this, SLOT(slotIrTry(unsigned int) ) );
32
33 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
34 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
35 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) );
36
37 chan = new QCopChannel("QPE/BluetoothBack", this );
38 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
39 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) );
40
41 QVBoxLayout* lay = new QVBoxLayout(this);
42
43 QHBox* nameBox = new QHBox(this);
44 QLabel* name = new QLabel(nameBox);
45 name->setText( tr("<qt><h1>Sending:</h1></qt>") );
46 name->setAlignment( AlignLeft | AlignTop );
47 m_lblFile = new QLabel(nameBox);
48 lay->addWidget(nameBox, 0);
49
50 QFrame* frame = new QFrame(this);
51 frame->setFrameShape( QFrame::HLine );
52 frame->setFrameShadow( QFrame::Sunken );
53 lay->addWidget(frame, 10);
54
55 QLabel* devices = new QLabel(this);
56 devices->setText("<qt><b>Devices:</b></qt>");
57 devices->setAlignment( AlignLeft | AlignTop );
58 lay->addWidget( devices,10 );
59
60 m_devBox = new DeviceBox(this);
61 lay->addWidget( m_devBox, 50 );
62 connect(m_devBox, SIGNAL(selectedDevice(int,int) ),
63 this, SLOT(slotSelectedDevice(int,int) ) );
64
65 QPushButton *but = new QPushButton(this);
66 but->setText(tr("Done") );
67 connect(but, SIGNAL(clicked() ),
68 this, SLOT(slotDone() ) );
69
70 lay->addWidget( but );
71 m_lay = lay;
72
73 // QT does not like if you add items to an layout which already exits....
74 // and was layouted invalidate() does not help too
75 // so we use RichText....
76}
77
78/*
79 * in send we'll first set everything up
80 * and then wait for a list of devices.
81 */
82void SendWidget::send( const QString& file, const QString& desc ) {
83 m_file = file;
84 m_irDa.clear();
85 m_start = 0;
86 m_lblFile->setText(desc.isEmpty() ? file : desc );
87
88 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) {
89 m_irDeSearch = m_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error );
90 m_start++;
91 }else
92 m_irDeSearch = m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search );
93
94 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
95 m_btDeSearch = m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error );
96 m_start++;
97 }else
98 m_btDeSearch = m_devBox->addDevice( tr("Searching for bluetooth Devices."), DeviceBox::Search );
99
100 if (m_start != 2 ) {
101 QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
102 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
103 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
104 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
105 }
106}
107void SendWidget::slotIrDaDevices( const QStringList& list) {
108 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
109 int id = m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
110 m_irDa.insert( id, (*it) );
111 }
112 m_devBox->removeDevice( m_irDeSearch );
113 m_irDaIt = m_irDa.begin();
114
115 slotStartIrda();
116}
117
118void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
119 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
120 int id = m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
121 m_bt.insert( id, Pair( it.key(), it.data() ) );
122 }
123 m_devBox->removeDevice( m_btDeSearch );
124}
125void SendWidget::slotSelectedDevice( int name, int ) {
126 if ( name == m_irDeSearch ) {
127 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
128 m_devBox->removeDevice( it.key() );
129
130 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
131 }
132}
133void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
134 if ( str == "devices(QStringList)" ) {
135 QDataStream stream( ar, IO_ReadOnly );
136 QStringList list;
137 stream >> list;
138 slotIrDaDevices( list );
139 }
140}
141void SendWidget::dispatchBt( const QCString&, const QByteArray& ) {
142
143}
144void SendWidget::slotIrError( int ) {
145
146}
147void SendWidget::slotIrSent( bool b) {
148 QString text = b ? tr("Sent") : tr("Failure");
149 m_devBox->setStatus( m_irDaIt.key(), text );
150 ++m_irDaIt;
151 slotStartIrda();
152}
153void SendWidget::slotIrTry(unsigned int trI) {
154 m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
155}
156void SendWidget::slotStartIrda() {
157 if (m_irDaIt == m_irDa.end() ) {
158 m_irDeSearch = m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
159 return;
160 }
161 m_devBox->setStatus( m_irDaIt.key(), tr("Start sending") );
162 m_obex->send( m_file );
163}
164void SendWidget::closeEvent( QCloseEvent* e) {
165 e->accept(); // make sure
166 QTimer::singleShot(0, this, SLOT(slotDone() ) );
167}
168void SendWidget::slotDone() {
169 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
170 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
171 emit done();
172}
173QString SendWidget::file()const {
174 return m_file;
175}
176DeviceBox::DeviceBox( QWidget* parent )
177 : QTextBrowser( parent ) {
178
179}
180DeviceBox::~DeviceBox() {
181
182}
183int DeviceBox::addDevice( const QString& name, int dev, const QString& status ) {
184 /* return a id for a range of devices */
185 int id = idFor ( dev );
186 DeviceItem item( name, status, dev,id );
187 m_dev.insert( id, item );
188 setText( allText() );
189
190 return id;
191}
192void DeviceBox::removeDevice( int id ) {
193 if (!m_dev.contains(id) ) return;
194
195 m_dev.remove( id );
196 setText( allText() );
197}
198void DeviceBox::setStatus( int id, const QString& status ) {
199 if ( !m_dev.contains(id) ) return;
200 m_dev[id].setStatus(status );
201 setText( allText() );
202}
203void DeviceBox::setSource( const QString& str ) {
204 int id = str.toInt();
205 emit selectedDevice( id, m_dev[id].device() );
206}
207int DeviceBox::idFor ( int id ) {
208 static int irId = 1501;
209 static int irBT = 1001;
210 static int irSr = 501;
211 static int irEr = 0;
212
213 int ret = -1;
214 switch(id ) {
215 case IrDa:
216 ret = irId;
217 irId++;
218 break;
219 case BT:
220 ret = irBT;
221 irBT++;
222 break;
223 case Search:
224 ret = irSr;
225 irSr++;
226 break;
227 case Error:
228 ret = irEr;
229 irEr++;
230 break;
231 }
232 return ret;
233}
234QString DeviceBox::allText() {
235 QString str;
236 typedef QMap<int, DeviceItem> DeviceMap;
237
238 for (QMap<int, DeviceItem>::Iterator it = m_dev.begin(); it != m_dev.end(); ++it ) {
239 str += it.data().toString() + "<br>";
240 }
241 return str;
242}
243
244DeviceItem::DeviceItem( const QString& name,
245 const QString& status, int dev, int id)
246{
247 m_name = name;
248 m_status = status;
249 m_dev = dev;
250 m_id = id;
251}
252int DeviceItem::id()const {
253 return m_id;
254}
255QString DeviceItem::name()const {
256 return m_name;
257}
258QString DeviceItem::status()const {
259 return m_status;
260}
261int DeviceItem::device()const {
262 return m_dev;
263}
264QString DeviceItem::pixmap()const{
265 QString str;
266 switch(m_dev) {
267 case DeviceBox::IrDa:
268 str ="obex/irda";
269 break;
270 case DeviceBox::BT:
271 str ="obex/bt";
272 break;
273 case DeviceBox::Search:
274 str = "mag";
275 break;
276 case DeviceBox::Error:
277 str = "editdelete";
278 break;
279 };
280 return str;
281}
282DeviceItem::~DeviceItem() {
283}
284void DeviceItem::setStatus(const QString& status ) {
285 m_status = status;
286}
287QString DeviceItem::toString()const {
288 return "<p><a href=\""+QString::number(m_id) +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ;
289}
diff --git a/core/obex/obexsend.h b/core/obex/obexsend.h
deleted file mode 100644
index bf901cb..0000000
--- a/core/obex/obexsend.h
+++ b/dev/null
@@ -1,125 +0,0 @@
1#ifndef OPIE_OBEX_SEND_WIDGET_H
2#define OPIE_OBEX_SEND_WIDGET_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6#include <qwidget.h>
7#include <qvbox.h>
8#include <qmap.h>
9#include <qtextbrowser.h>
10
11class QLabel;
12class QVBoxLayout;
13/**
14 * This is the new sending widget for Obex
15 * It will attemp to smart and be able to send
16 * it to multiple devices.
17 * It'll support BT + IrDa
18 */
19namespace OpieObex {
20 class DeviceBox;
21 class Obex;
22
23 struct Pair {
24 Pair(const QString& first = QString::null,
25 const QString& second = QString::null)
26 : m_first(first), m_second(second ) {
27 }
28 QString first()const{ return m_first; }
29 QString second()const { return m_second; }
30 private:
31 QString m_first;
32 QString m_second;
33 };
34 class SendWidget : public QWidget{
35 Q_OBJECT
36 public:
37 SendWidget( QWidget* parent = 0, const char* name = 0);
38 ~SendWidget();
39
40 QString file()const;
41
42 protected:
43 void closeEvent( QCloseEvent* );
44
45 public slots:
46 void send( const QString& file, const QString& desc );
47
48 signals:
49 void done();
50
51 private slots: // QCOP slots
52 /* IrDa Names*/
53 void slotIrDaDevices( const QStringList& );
54 /* Bt Names + BD-Addr */
55 void slotBTDevices( const QMap<QString, QString>& );
56 void slotSelectedDevice( int id, int dev );
57 void dispatchIrda( const QCString& str, const QByteArray& ar );
58 void dispatchBt( const QCString& str, const QByteArray& ar );
59
60 void slotIrError( int );
61 void slotIrSent(bool);
62 void slotIrTry(unsigned int );
63 void slotStartIrda();
64 void slotDone();
65 private:
66 void initUI();
67 QLabel* m_lblFile;
68 DeviceBox* m_devBox;
69 QVBoxLayout* m_lay;
70 int m_start;
71 QMap<int, QString> m_irDa;
72 QMap<int, QString>::Iterator m_irDaIt;
73 QMap<int, Pair > m_bt;
74 QString m_file;
75 Obex* m_obex;
76 int m_irDeSearch; // search of irda and bt devices
77 int m_btDeSearch;
78 };
79 class DeviceItem {
80 public:
81 DeviceItem( const QString& name = QString::null,
82 const QString& status = QString::null, int dev = 3, int id = -1);
83 ~DeviceItem();
84 void setStatus( const QString& text );
85
86 QString name()const;
87 QString status()const;
88 QString pixmap()const;
89 int device()const;
90 int id()const;
91 QString toString()const;
92 private:
93 QString m_name;
94 QString m_status;
95 int m_dev;
96 int m_id;
97 };
98
99 /*
100 * The text field which contains the information about sending...
101 *
102 */
103 class DeviceBox : public QTextBrowser {
104 Q_OBJECT
105 public:
106 enum Device { IrDa, BT, Search, Error };
107 DeviceBox( QWidget* parent );
108 ~DeviceBox();
109
110 void setSource( const QString& str );
111 int addDevice( const QString& name, int dev,
112 const QString& status = QString::null );
113 void removeDevice( int );
114 void setStatus( int, const QString& );
115 signals:
116 void selectedDevice( int id, int dev );
117 private:
118 /* returns a id for a device from a device range */
119 int idFor (int deviceType );
120 QString allText();
121 QMap<int, DeviceItem> m_dev;
122 };
123}
124
125#endif