summaryrefslogtreecommitdiff
path: root/core/obex/obexsend.cpp
authorzecke <zecke>2003-02-16 15:49:02 (UTC)
committer zecke <zecke>2003-02-16 15:49:02 (UTC)
commit30a098530260176ac20d75ba6cb7abfb3d998c13 (patch) (unidiff)
treeee5c08ca67fa00574414153921ab2de654c60421 /core/obex/obexsend.cpp
parent7fab90d46144843d32e476ada8d0a5f40f50aa60 (diff)
downloadopie-30a098530260176ac20d75ba6cb7abfb3d998c13.zip
opie-30a098530260176ac20d75ba6cb7abfb3d998c13.tar.gz
opie-30a098530260176ac20d75ba6cb7abfb3d998c13.tar.bz2
disable snd in IrDaApplet it hangs on my machine..
Remove the hacky OBEX Implementation Add a more cleaned up more appealing (not yet working) version which will even be able to do OBEX over Bluetooth in the future -It handles receive better let's you choose what to do with custom files and created a DocLnk -Send lets you beam to multiple devices this needs the IrDa Applet to be present
Diffstat (limited to 'core/obex/obexsend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexsend.cpp251
1 files changed, 251 insertions, 0 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
new file mode 100644
index 0000000..a2e4c16
--- a/dev/null
+++ b/core/obex/obexsend.cpp
@@ -0,0 +1,251 @@
1#include <qpushbutton.h>
2#include <qlabel.h>
3#include <qhbox.h>
4#include <qlayout.h>
5#include <qtimer.h>
6
7#include <qcopchannel_qws.h>
8
9#include <qpe/resource.h>
10#include <qpe/qcopenvelope_qws.h>
11
12#include "obex.h"
13#include "obexsend.h"
14
15using namespace OpieObex;
16
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(dispatchBt(const QCString&, const QByteArray& ) ) );
36
37 chan = new QCopChannel("QPE/BluetoothBack", this );
38 connect(chan, SIGNAL(received(const QCString&, const QByteArray& ) ),
39 this, SLOT(dispatchIrda(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(const QString&, int ) ),
63 this, SLOT(slotSelectedDevice(const QString&, 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_devBox->addDevice( tr("IrDa is not enabled!"), DeviceBox::Error );
90 m_start++;
91 }else
92 m_devBox->addDevice( tr("Searching for IrDa Devices."), DeviceBox::Search );
93
94 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
95 m_devBox->addDevice( tr("Bluetooth is not available"), DeviceBox::Error );
96 m_start++;
97 }else
98 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 QTimer::singleShot(5000, this, SLOT(testIt() ) );
107}
108void SendWidget::slotIrDaDevices( const QStringList& list) {
109 m_irDa = list;
110 m_start = 0;
111 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it )
112 m_devBox->addDevice( (*it), DeviceBox::IrDa, tr("Scheduling for beam.") );
113 m_devBox->removeDevice( tr("Search for IrDa Devices.") );
114
115 slotStartIrda();
116}
117void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
118 m_bt = str;
119 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
120 m_devBox->addDevice( it.key(), DeviceBox::BT, tr("Click to beam") );
121 }
122 m_devBox->removeDevice( tr("Searching for bluetooth Devices.") );
123}
124void SendWidget::slotSelectedDevice( const QString& name, int dev ) {
125 qWarning("Start beam? %s %d", name.latin1(), dev );
126 if ( name == tr("Search again for IrDa.") ) {
127 for (QStringList::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
128 m_devBox->removeDevice( (*it) );
129 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
130 }
131}
132void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
133 qWarning("dispatch irda %s", str.data() );
134 if ( str == "listDevices(QStringList)" ) {
135 QDataStream stream( ar, IO_ReadOnly );
136 QStringList list;
137 stream >> list;
138 slotIrDaDevices( list );
139 }
140}
141void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
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_irDa[m_start], text );
150 m_start++;
151 slotStartIrda();
152}
153void SendWidget::slotIrTry(unsigned int trI) {
154 m_devBox->setStatus( m_irDa[m_start], tr("Try %1").arg( QString::number( trI ) ) );
155}
156void SendWidget::slotStartIrda() {
157 if (m_start >= m_irDa.count() ) {
158 m_devBox->addDevice(tr("Search again for IrDa."), DeviceBox::Search );
159 return;
160 }
161 m_devBox->setStatus( m_irDa[m_start], tr("Start sending") );
162 m_obex->send( m_file );
163}
164void SendWidget::slotDone() {
165 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
166 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
167 emit done();
168}
169QString SendWidget::file()const {
170 return m_file;
171}
172DeviceBox::DeviceBox( QWidget* parent )
173 : QTextBrowser( parent ) {
174
175}
176DeviceBox::~DeviceBox() {
177
178}
179void DeviceBox::addDevice( const QString& name, int dev, const QString& status ) {
180 QString tex;
181 DeviceItem item( name, status, dev );
182 m_dev.insert( name, item );
183 tex = item.toString();
184 m_devices.prepend(tex);
185 setText( text()+ "<br>"+tex );
186}
187void DeviceBox::removeDevice( const QString& name ) {
188 if (!m_dev.contains(name) ) return;
189 m_devices.remove( m_dev[name].toString() );
190
191 m_dev.remove(name);
192 setText( m_devices.join("<br>") );
193
194}
195void DeviceBox::setStatus( const QString& name, const QString& status ) {
196 if ( !m_dev.contains(name) ) return;
197 DeviceItem dev = m_dev[name];
198 QString ole = dev.toString();
199 dev.setStatus( status );
200 int index = m_devices.findIndex( ole );
201 m_devices[index] = dev.toString();
202 setText( m_devices.join("<br>") );
203}
204void DeviceBox::setSource( const QString& str ) {
205 qWarning("SetSource:%s", str.latin1() );
206 emit selectedDevice( str, m_dev[str].device() );
207}
208
209
210DeviceItem::DeviceItem( const QString& name,
211 const QString& status, int dev)
212{
213 m_name = name;
214 m_status = status;
215 m_dev = dev;
216}
217QString DeviceItem::name()const {
218 return m_name;
219}
220QString DeviceItem::status()const {
221 return m_status;
222}
223int DeviceItem::device()const {
224 return m_dev;
225}
226QString DeviceItem::pixmap()const{
227 QString str;
228 switch(m_dev) {
229 case DeviceBox::IrDa:
230 str ="obex/irda";
231 break;
232 case DeviceBox::BT:
233 str ="obex/bt";
234 break;
235 case DeviceBox::Search:
236 str = "obex/search";
237 break;
238 case DeviceBox::Error:
239 str = "editdelete";
240 break;
241 };
242 return str;
243}
244DeviceItem::~DeviceItem() {
245}
246void DeviceItem::setStatus(const QString& status ) {
247 m_status = status;
248}
249QString DeviceItem::toString()const {
250 return "<p><a href=\""+m_name +"\" ><img src=\""+pixmap()+"\" >"+m_name+" "+m_status+" </a></p>" ;
251}