summaryrefslogtreecommitdiff
path: root/core/obex/obexsend.cpp
authormickeyl <mickeyl>2005-08-23 09:55:13 (UTC)
committer mickeyl <mickeyl>2005-08-23 09:55:13 (UTC)
commitb08c3417b7635a90879fdcc61b95b0f34c5ca813 (patch) (unidiff)
tree5b0083dc0a49abcb1d20da441bbe35d8199f9a38 /core/obex/obexsend.cpp
parent15fc46c76afa55fbfaab54c4de3fedd4613e3712 (diff)
downloadopie-b08c3417b7635a90879fdcc61b95b0f34c5ca813.zip
opie-b08c3417b7635a90879fdcc61b95b0f34c5ca813.tar.gz
opie-b08c3417b7635a90879fdcc61b95b0f34c5ca813.tar.bz2
readd some files again
Diffstat (limited to 'core/obex/obexsend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/obex/obexsend.cpp234
1 files changed, 234 insertions, 0 deletions
diff --git a/core/obex/obexsend.cpp b/core/obex/obexsend.cpp
new file mode 100644
index 0000000..a80a48b
--- a/dev/null
+++ b/core/obex/obexsend.cpp
@@ -0,0 +1,234 @@
1// 7-Jul-2005 mbh@sdgsystems.com: replace hand coded form with one
2// generated via QT2 Designer. The new form supports
3// selection of target devices, as opposed to sending to
4// all.
5
6#include "obex.h"
7#include "btobex.h"
8#include "obexsend.h"
9using namespace OpieObex;
10
11/* OPIE */
12#include <opie2/odebug.h>
13#include <qpe/qcopenvelope_qws.h>
14#include <qpe/resource.h>
15
16using namespace Opie::Core;
17
18/* QT */
19#include <qlabel.h>
20#include <qpixmap.h>
21#include <qlistview.h>
22#include <qtimer.h>
23
24/* TRANSLATOR OpieObex::SendWidget */
25
26SendWidget::SendWidget( QWidget* parent, const char* name )
27 : obexSendBase( parent, name ) {
28 initUI();
29}
30SendWidget::~SendWidget() {
31}
32void SendWidget::initUI() {
33 m_obex = new Obex(this, "obex");
34 connect(m_obex, SIGNAL(error(int) ),
35 this, SLOT(slotIrError(int) ) );
36 connect(m_obex, SIGNAL(sent(bool) ),
37 this, SLOT(slotIrSent(bool) ) );
38 connect(m_obex, SIGNAL(currentTry(unsigned int) ),
39 this, SLOT(slotIrTry(unsigned int) ) );
40
41 QCopChannel* chan = new QCopChannel("QPE/IrDaAppletBack", this );
42 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
43 this, SLOT(dispatchIrda(const QCString&,const QByteArray&) ) );
44
45 m_btobex = new BtObex(this, "btobex");
46 connect(m_btobex, SIGNAL(error(int) ),
47 this, SLOT(slotBtError(int) ) );
48 connect(m_btobex, SIGNAL(sent(bool) ),
49 this, SLOT(slotBtSent(bool) ) );
50 connect(m_btobex, SIGNAL(currentTry(unsigned int) ),
51 this, SLOT(slotBtTry(unsigned int) ) );
52
53 chan = new QCopChannel("QPE/BluetoothBack", this );
54 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
55 this, SLOT(dispatchBt(const QCString&,const QByteArray&) ) );
56
57}
58
59/*
60 * in send we'll first set everything up
61 * and then wait for a list of devices.
62 */
63void SendWidget::send( const QString& file, const QString& desc ) {
64 m_file = file;
65 m_irDa.clear();
66 m_start = 0;
67
68 fileToSend->setText(desc.isEmpty() ? file : desc );
69 scan_for_receivers();
70}
71
72int SendWidget::addReceiver(const char *r, const char *icon)
73{
74 QListViewItem * item = new QListViewItem( receiverList, 0 );
75 item->setText( 0, r);
76 item->setPixmap( 1, Resource::loadPixmap( icon ) );
77
78 int id=receivers.count();
79 receivers[id]=item;
80 return id;
81}
82
83bool SendWidget::receiverSelected(int id)
84{
85 return receivers[id]->pixmap(2);
86}
87
88void SendWidget::setReceiverStatus( int id, const QString& status ) {
89 if ( !receivers.contains(id) ) return;
90 receivers[id]->setText(3, status );
91}
92
93void SendWidget::slotIrDaDevices( const QStringList& list) {
94 for (QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
95 int id = addReceiver(*it, "obex/irda.png");
96 m_irDa.insert( id, (*it) );
97 }
98 irdaStatus->setText( tr("ready."));
99 m_irDaIt = m_irDa.begin();
100
101}
102
103void SendWidget::slotBTDevices( const QMap<QString, QString>& str ) {
104 for(QMap<QString, QString>::ConstIterator it = str.begin(); it != str.end(); ++it ) {
105 int id = addReceiver(it.key(), "obex/bt.png");
106 m_bt.insert( id, Pair( it.key(), it.data() ) );
107 }
108 btStatus->setText(tr("ready."));
109 m_btIt = m_bt.begin();
110
111}
112void SendWidget::slotSelectedDevice( int, int ) {
113/* if ( name == m_irDeSearch ) {
114 for (QMap<int, QString>::Iterator it= m_irDa.begin(); it != m_irDa.end(); ++it )
115 m_devBox->removeDevice( it.key() );
116
117 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
118 }*/
119}
120void SendWidget::dispatchIrda( const QCString& str, const QByteArray& ar ) {
121 if ( str == "devices(QStringList)" ) {
122 QDataStream stream( ar, IO_ReadOnly );
123 QStringList list;
124 stream >> list;
125 slotIrDaDevices( list );
126 }
127}
128void SendWidget::slotIrError( int ) {
129 irdaStatus->setText(tr("error :("));
130}
131void SendWidget::slotIrSent( bool b) {
132 QString text = b ? tr("Sent") : tr("Failure");
133 setReceiverStatus( m_irDaIt.key(), text );
134 ++m_irDaIt;
135 slotStartIrda();
136}
137void SendWidget::slotIrTry(unsigned int trI) {
138 setReceiverStatus(m_irDaIt.key(), tr("Try %1").arg( QString::number( trI ) ));
139}
140void SendWidget::slotStartIrda() {
141 if (m_irDaIt == m_irDa.end() ) {
142 irdaStatus->setText(tr("complete."));
143 return;
144 }
145 setReceiverStatus( m_irDaIt.key(), tr("Start sending") );
146 m_obex->send( m_file );
147}
148
149void SendWidget::dispatchBt( const QCString& str, const QByteArray& ar ) {
150 if ( str == "devices(QStringMap)" ) {
151 QDataStream stream( ar, IO_ReadOnly );
152 QMap<QString, QString> btmap;
153 stream >> btmap;
154 slotBTDevices( btmap );
155 }
156}
157void SendWidget::slotBtError( int ) {
158 btStatus->setText(tr("error :("));
159}
160void SendWidget::slotBtSent( bool b) {
161 QString text = b ? tr("Sent") : tr("Failure");
162 setReceiverStatus( m_btIt.key(), text );
163 ++m_btIt;
164 slotStartBt();
165}
166void SendWidget::slotBtTry(unsigned int trI) {
167 setReceiverStatus( m_btIt.key(), tr("Try %1").arg( QString::number( trI ) ) );
168}
169void SendWidget::slotStartBt() {
170 // skip past unselected receivers
171 while((m_btIt != m_bt.end()) && !receiverSelected(m_btIt.key()))
172 ++m_btIt;
173 if (m_btIt == m_bt.end() ) {
174 btStatus->setText(tr("complete."));
175 return;
176 }
177 setReceiverStatus( m_btIt.key(), tr("Start sending") );
178 m_btobex->send( m_file, m_btIt.data().second() );
179}
180
181void SendWidget::send_to_receivers() {
182 slotStartIrda();
183 slotStartBt();
184}
185
186void SendWidget::scan_for_receivers() {
187
188 bool enable_irda=false;
189 bool enable_bt=false;
190
191 if ( !QCopChannel::isRegistered("QPE/IrDaApplet") ) {
192 irdaStatus->setText(tr("not enabled."));
193 enable_irda=true;
194 } else
195 irdaStatus->setText(tr("searching..."));
196
197 if ( !QCopChannel::isRegistered("QPE/Bluetooth") ) {
198 btStatus->setText(tr("not enabled."));
199 enable_bt=true;
200 } else
201 btStatus->setText(tr("searching..."));
202
203 if (enable_irda)
204 QCopEnvelope e0("QPE/IrDaApplet", "enableIrda()");
205 if (enable_bt)
206 QCopEnvelope e1("QPE/Bluetooth", "enableBluetooth()");
207
208 QCopEnvelope e2("QPE/IrDaApplet", "listDevices()");
209 QCopEnvelope e3("QPE/Bluetooth", "listDevices()");
210
211}
212
213void SendWidget::toggle_receiver(QListViewItem* item)
214{
215 // toggle the state of an individual receiver.
216 if(item->pixmap(2))
217 item->setPixmap(2,QPixmap());
218 else
219 item->setPixmap(2,Resource::loadPixmap("backup/check.png"));
220}
221
222
223void SendWidget::closeEvent( QCloseEvent* e) {
224 e->accept(); // make sure
225 QTimer::singleShot(0, this, SLOT(userDone() ) );
226}
227void SendWidget::userDone() {
228 QCopEnvelope e0("QPE/IrDaApplet", "disableIrda()");
229 QCopEnvelope e1("QPE/Bluetooth", "disableBluetooth()");
230 emit done();
231}
232QString SendWidget::file()const {
233 return m_file;
234}