-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.pro | 10 | ||||
-rw-r--r-- | core/obex/obexsend.cpp | 289 | ||||
-rw-r--r-- | core/obex/obexsend.h | 125 |
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,5 +1,5 @@ | |||
1 | 1 | ||
2 | #include "obex.h" | 2 | #include "btobex.h" |
3 | 3 | ||
4 | /* OPIE */ | 4 | /* OPIE */ |
5 | #include <opie2/oprocess.h> | 5 | #include <opie2/oprocess.h> |
@@ -15,7 +15,7 @@ using namespace OpieObex; | |||
15 | using namespace Opie::Core; | 15 | using namespace Opie::Core; |
16 | /* TRANSLATOR OpieObex::Obex */ | 16 | /* TRANSLATOR OpieObex::Obex */ |
17 | 17 | ||
18 | Obex::Obex( QObject *parent, const char* name ) | 18 | BtObex::BtObex( QObject *parent, const char* name ) |
19 | : QObject(parent, name ) | 19 | : QObject(parent, name ) |
20 | { | 20 | { |
21 | m_rec = 0; | 21 | m_rec = 0; |
@@ -27,15 +27,17 @@ Obex::Obex( QObject *parent, const char* name ) | |||
27 | connect( this, SIGNAL(sent(bool) ), | 27 | connect( this, SIGNAL(sent(bool) ), |
28 | SLOT(slotError() ) ); | 28 | SLOT(slotError() ) ); |
29 | }; | 29 | }; |
30 | Obex::~Obex() { | 30 | BtObex::~BtObex() { |
31 | delete m_rec; | 31 | delete m_rec; |
32 | delete m_send; | 32 | delete m_send; |
33 | } | 33 | } |
34 | void Obex::receive() { | 34 | void BtObex::receive() { |
35 | m_receive = true; | 35 | m_receive = true; |
36 | m_outp = QString::null; | 36 | m_outp = QString::null; |
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 |
40 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), | 42 | connect(m_rec, SIGNAL(processExited(Opie::Core::OProcess*) ), |
41 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); | 43 | this, SLOT(slotExited(Opie::Core::OProcess*) ) ); |
@@ -50,9 +52,11 @@ void Obex::receive() { | |||
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
53 | void Obex::send( const QString& fileName) { // if currently receiving stop it send receive | 55 | void 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 ) { |
57 | if (m_rec->isRunning() ) { | 61 | if (m_rec->isRunning() ) { |
58 | emit error(-1 ); | 62 | emit error(-1 ); |
@@ -66,7 +70,7 @@ void Obex::send( const QString& fileName) { // if currently receiving stop it se | |||
66 | } | 70 | } |
67 | sendNow(); | 71 | sendNow(); |
68 | } | 72 | } |
69 | void Obex::sendNow(){ | 73 | void BtObex::sendNow(){ |
70 | if ( m_count >= 25 ) { // could not send | 74 | if ( m_count >= 25 ) { // could not send |
71 | emit error(-1 ); | 75 | emit error(-1 ); |
72 | emit sent(false); | 76 | emit sent(false); |
@@ -76,8 +80,12 @@ void Obex::sendNow(){ | |||
76 | m_send = new OProcess(); | 80 | m_send = new OProcess(); |
77 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); | 81 | m_send->setWorkingDirectory( QFileInfo(m_file).dirPath(true) ); |
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 | ||
82 | // connect to slots Exited and and StdOut | 90 | // connect to slots Exited and and StdOut |
83 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), | 91 | connect(m_send, SIGNAL(processExited(Opie::Core::OProcess*) ), |
@@ -97,14 +105,14 @@ void Obex::sendNow(){ | |||
97 | emit currentTry( m_count ); | 105 | emit currentTry( m_count ); |
98 | } | 106 | } |
99 | 107 | ||
100 | void Obex::slotExited(OProcess* proc ){ | 108 | void BtObex::slotExited(OProcess* proc ){ |
101 | if (proc == m_rec ) // receive process | 109 | if (proc == m_rec ) // receive process |
102 | received(); | 110 | received(); |
103 | else if ( proc == m_send ) | 111 | else if ( proc == m_send ) |
104 | sendEnd(); | 112 | sendEnd(); |
105 | 113 | ||
106 | } | 114 | } |
107 | void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | 115 | void BtObex::slotStdOut(OProcess* proc, char* buf, int len){ |
108 | if ( proc == m_rec ) { // only receive | 116 | if ( proc == m_rec ) { // only receive |
109 | QByteArray ar( len ); | 117 | QByteArray ar( len ); |
110 | memcpy( ar.data(), buf, len ); | 118 | memcpy( ar.data(), buf, len ); |
@@ -112,7 +120,7 @@ void Obex::slotStdOut(OProcess* proc, char* buf, int len){ | |||
112 | } | 120 | } |
113 | } | 121 | } |
114 | 122 | ||
115 | void Obex::received() { | 123 | void BtObex::received() { |
116 | if (m_rec->normalExit() ) { | 124 | if (m_rec->normalExit() ) { |
117 | if ( m_rec->exitStatus() == 0 ) { // we got one | 125 | if ( m_rec->exitStatus() == 0 ) { // we got one |
118 | QString filename = parseOut(); | 126 | QString filename = parseOut(); |
@@ -126,7 +134,7 @@ void Obex::received() { | |||
126 | receive(); | 134 | receive(); |
127 | } | 135 | } |
128 | 136 | ||
129 | void Obex::sendEnd() { | 137 | void BtObex::sendEnd() { |
130 | if (m_send->normalExit() ) { | 138 | if (m_send->normalExit() ) { |
131 | if ( m_send->exitStatus() == 0 ) { | 139 | if ( m_send->exitStatus() == 0 ) { |
132 | delete m_send; | 140 | delete m_send; |
@@ -144,7 +152,9 @@ void Obex::sendEnd() { | |||
144 | m_send = 0; | 152 | m_send = 0; |
145 | } | 153 | } |
146 | } | 154 | } |
147 | QString Obex::parseOut( ){ | 155 | |
156 | // This probably doesn't do anything useful for bt. | ||
157 | QString BtObex::parseOut( ){ | ||
148 | QString path; | 158 | QString path; |
149 | QStringList list = QStringList::split("\n", m_outp); | 159 | QStringList list = QStringList::split("\n", m_outp); |
150 | QStringList::Iterator it; | 160 | QStringList::Iterator it; |
@@ -164,18 +174,18 @@ QString Obex::parseOut( ){ | |||
164 | /** | 174 | /** |
165 | * when sent is done slotError is called we will start receive again | 175 | * when sent is done slotError is called we will start receive again |
166 | */ | 176 | */ |
167 | void Obex::slotError() { | 177 | void BtObex::slotError() { |
168 | if ( m_receive ) | 178 | if ( m_receive ) |
169 | receive(); | 179 | receive(); |
170 | }; | 180 | }; |
171 | void Obex::setReceiveEnabled( bool receive ) { | 181 | void BtObex::setReceiveEnabled( bool receive ) { |
172 | if ( !receive ) { // | 182 | if ( !receive ) { // |
173 | m_receive = false; | 183 | m_receive = false; |
174 | shutDownReceive(); | 184 | shutDownReceive(); |
175 | } | 185 | } |
176 | } | 186 | } |
177 | 187 | ||
178 | void Obex::shutDownReceive() { | 188 | void BtObex::shutDownReceive() { |
179 | if (m_rec != 0 ) { | 189 | if (m_rec != 0 ) { |
180 | if (m_rec->isRunning() ) { | 190 | if (m_rec->isRunning() ) { |
181 | emit error(-1 ); | 191 | emit error(-1 ); |
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 | |||
@@ -1,31 +1,32 @@ | |||
1 | 1 | ||
2 | 2 | ||
3 | #ifndef OpieObex_H | 3 | #ifndef OpieBtObex_H |
4 | #define OpieObex_H | 4 | #define OpieBtObex_H |
5 | 5 | ||
6 | #include <qobject.h> | 6 | #include <qobject.h> |
7 | 7 | ||
8 | namespace Opie {namespace Core {class OProcess;}} | 8 | namespace Opie {namespace Core {class OProcess;}} |
9 | class QCopChannel; | 9 | class QCopChannel; |
10 | namespace OpieObex { | 10 | namespace 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 |
13 | public: | 14 | public: |
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 | /** |
19 | * d'tor | 20 | * d'tor |
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 |
26 | */ | 27 | */ |
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 ); |
30 | signals: | 31 | signals: |
31 | 32 | ||
@@ -53,6 +54,7 @@ namespace OpieObex { | |||
53 | uint m_count; | 54 | uint m_count; |
54 | QString m_file; | 55 | QString m_file; |
55 | QString m_outp; | 56 | QString m_outp; |
57 | QString m_bdaddr; | ||
56 | Opie::Core::OProcess *m_send; | 58 | Opie::Core::OProcess *m_send; |
57 | Opie::Core::OProcess *m_rec; | 59 | Opie::Core::OProcess *m_rec; |
58 | bool m_receive : 1; | 60 | bool m_receive : 1; |
@@ -60,12 +62,6 @@ namespace OpieObex { | |||
60 | 62 | ||
61 | private slots: | 63 | 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 |
70 | void slotExited(Opie::Core::OProcess* proc) ; | 66 | void slotExited(Opie::Core::OProcess* proc) ; |
71 | void slotStdOut(Opie::Core::OProcess*, char*, int); | 67 | void slotStdOut(Opie::Core::OProcess*, char*, int); |
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 | |||
@@ -1,13 +1,13 @@ | |||
1 | TEMPLATE= lib | 1 | 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 |
7 | INTERFACES = obexsendbase.ui | ||
7 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher | 8 | INCLUDEPATH += $(OPIEDIR)/include $(OPIEDIR)/core/launcher |
8 | DEPENDPATH += | 9 | LIBS += -lqpe -lopiecore2 |
9 | LIBS += -lqpe -lopiecore2 | 10 | VERSION = 0.0.3 |
10 | VERSION = 0.0.2 | ||
11 | 11 | ||
12 | include( $(OPIEDIR)/include.pro ) | 12 | include( $(OPIEDIR)/include.pro ) |
13 | target.path = $$prefix/plugins/applets | 13 | target.path = $$prefix/plugins/applets |
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" | ||
3 | using namespace OpieObex; | ||
4 | |||
5 | /* OPIE */ | ||
6 | #include <opie2/odebug.h> | ||
7 | #include <qpe/qcopenvelope_qws.h> | ||
8 | using 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 | |||
18 | SendWidget::SendWidget( QWidget* parent, const char* name ) | ||
19 | : QWidget( parent, name ) { | ||
20 | initUI(); | ||
21 | } | ||
22 | SendWidget::~SendWidget() { | ||
23 | } | ||
24 | void 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 | */ | ||
82 | void 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 | } | ||
107 | void 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 | |||
118 | void 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 | } | ||
125 | void 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 | } | ||
133 | void 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 | } | ||
141 | void SendWidget::dispatchBt( const QCString&, const QByteArray& ) { | ||
142 | |||
143 | } | ||
144 | void SendWidget::slotIrError( int ) { | ||
145 | |||
146 | } | ||
147 | void 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 | } | ||
153 | void SendWidget::slotIrTry(unsigned int trI) { | ||
154 | m_devBox->setStatus( m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ) ); | ||
155 | } | ||
156 | void 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 | } | ||
164 | void SendWidget::closeEvent( QCloseEvent* e) { | ||
165 | e->accept(); // make sure | ||
166 | QTimer::singleShot(0, this, SLOT(slotDone() ) ); | ||
167 | } | ||
168 | void SendWidget::slotDone() { | ||
169 | QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()"); | ||
170 | QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()"); | ||
171 | emit done(); | ||
172 | } | ||
173 | QString SendWidget::file()const { | ||
174 | return m_file; | ||
175 | } | ||
176 | DeviceBox::DeviceBox( QWidget* parent ) | ||
177 | : QTextBrowser( parent ) { | ||
178 | |||
179 | } | ||
180 | DeviceBox::~DeviceBox() { | ||
181 | |||
182 | } | ||
183 | int 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 | } | ||
192 | void DeviceBox::removeDevice( int id ) { | ||
193 | if (!m_dev.contains(id) ) return; | ||
194 | |||
195 | m_dev.remove( id ); | ||
196 | setText( allText() ); | ||
197 | } | ||
198 | void DeviceBox::setStatus( int id, const QString& status ) { | ||
199 | if ( !m_dev.contains(id) ) return; | ||
200 | m_dev[id].setStatus(status ); | ||
201 | setText( allText() ); | ||
202 | } | ||
203 | void DeviceBox::setSource( const QString& str ) { | ||
204 | int id = str.toInt(); | ||
205 | emit selectedDevice( id, m_dev[id].device() ); | ||
206 | } | ||
207 | int 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 | } | ||
234 | QString 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 | |||
244 | DeviceItem::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 | } | ||
252 | int DeviceItem::id()const { | ||
253 | return m_id; | ||
254 | } | ||
255 | QString DeviceItem::name()const { | ||
256 | return m_name; | ||
257 | } | ||
258 | QString DeviceItem::status()const { | ||
259 | return m_status; | ||
260 | } | ||
261 | int DeviceItem::device()const { | ||
262 | return m_dev; | ||
263 | } | ||
264 | QString 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 | } | ||
282 | DeviceItem::~DeviceItem() { | ||
283 | } | ||
284 | void DeviceItem::setStatus(const QString& status ) { | ||
285 | m_status = status; | ||
286 | } | ||
287 | QString 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 | |||
11 | class QLabel; | ||
12 | class 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 | */ | ||
19 | namespace 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 | ||